0% found this document useful (0 votes)
7 views11 pages

SQL Update and Delete Statment

The document provides an overview of SQL UPDATE and DELETE statements, detailing their syntax and usage. It emphasizes the importance of the WHERE clause to avoid unintended updates or deletions of all records in a table. Additionally, it includes examples of updating records, adding new columns with ALTER TABLE, and deleting records or entire tables.

Uploaded by

zainab.haider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

SQL Update and Delete Statment

The document provides an overview of SQL UPDATE and DELETE statements, detailing their syntax and usage. It emphasizes the importance of the WHERE clause to avoid unintended updates or deletions of all records in a table. Additionally, it includes examples of updating records, adding new columns with ALTER TABLE, and deleting records or entire tables.

Uploaded by

zainab.haider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

sql update and delete statment

lab

by:Zaineb Haider and Zainab Mohammed


The SQL UPDATE Statement
The UPDATE statement is used to modify the existing records in a
table.
UPDATE Syntax

UPDATE table_name ‫اسم الجدول‬


SET column1 = value1, column2 = value2, ...
2‫الحقل‬,1‫الحقل‬,
WHERE condition; ‫الشرط‬
Note:
Be careful when updating records in a table! Notice the
WHERE clause in the UPDATE statement. The WHERE clause
specifies which record(s) that should be updated. If you omit
the WHERE clause, all records in the table will be updated!
‫عند تحديث القيود في الجدول يجب وضع الشرط مع جملة‬
‫حيث انها تحدد اي قيد سيتم تحديثه وبخالفه سيتم‬.‫التحديث‬
‫تحديث الحقل بالكامل‬.
The following SQL statement updates
the first customer (CustomerID = 1)
with a new name and a new city.
UPDATE Customers
SET first_name = 'josh', City= 'Frankfurt'
WHERE CustomerID = 2;
UPDATE Multiple Records ‫تحديث كل‬
‫القيود‬
It is the WHERE clause that determines how many records will be
updated.
‫الجملة الشرطية هي التي نحدد بها عدد القيود التي يتم تحديثها‬.
The following SQL statement will update the product_name to "ipad"
for all records where first_name is "josh":
UPDATE Customers
SET product_name='iphone'
WHERE first_name='josh'
select*from customers;
Update Warning!
Be careful when updating records. If you omit the WHERE clause, ALL
records will be updated!
‫عند اهمال الجملة الشرطية وعدم تحديد القيد المراد التعديل عليه سيتم‬
‫تحديث كل قيود الجدول‬
Example
UPDATE Customers
SET product_name='ipad';
ALTER TABLE statement
To add a new column to an existing table in SQL, you use the
ALTER TABLE statement. Here's the general syntax:
‫نستخدم عبارة‬
ALTER ‫الضافة حقل جديد لجدول موجود‬
ALTER TABLE table_name ‫اسم الجدول‬
ADD column_name data_type; ‫اس<<م الحق<<ل ون<<وع‬
‫البيانات‬
example:here we add a column that
named as email and type is varchar
ALTER TABLE customers
ADD phone VARCHAR(100);
select*from customers;
The SQL DELETE Statement
The DELETE statement is used to delete existing records in a table.
DELETE Syntax:‫تستخدم لحذف قيد في الجدول‬

DELETE FROM table_name WHERE condition;

Note: Be careful when deleting records in a table! Notice the WHERE


clause in the DELETE statement. The WHERE clause specifies which
record(s) should be deleted. If you omit the WHERE clause, all records
in the table will be deleted!
The following SQL statement deletes the
customer "josh" from the "Customers" table:
DELETE FROM Customers WHERE first_name='josh';

Delete All Records


DELETE FROM table_name;
Delete a Table

To delete the table completely, use the DROP TABLE statement:

DROP TABLE Customers;

You might also like