The SQL DELETE Statement
The DELETE
statement is used to delete existing records in a table.
DELETE Syntax
DELETE FROM table_name WHERE condition;
Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:
CustomerID | CustomerName | City | PostalCode | Country | ||
---|---|---|---|---|---|---|
1 | Jamdhade Tushar | Newasa | 12209 | India | ||
2 | Jamdhade Atharv | Shrirampur | 05021 | India | ||
3 | Jamdhade Sagar | Pune | 05023 | India | ||
4 | Jamdhade Gaurav | Mumbai | WA1 1DP | India | ||
5 | Jamdhade Tush | Deli | S-958 22 | India |
SQL DELETE Example
The following SQL statement deletes the customer "Alfreds Futterkiste" from the "Customers" table:
Example
DELETE FROM Customers WHERE CustomerName='Jamdhade Tushar';
The "Customers" table will now look like this:
CustomerID | CustomerName | City | PostalCode | Country | ||
---|---|---|---|---|---|---|
2 | Jamdhade Atharv | Shrirampur | 05021 | Mexico | ||
3 | Jamdhade Sagar | Pune | 05023 | Mexico | ||
4 | Jamdhade Gaurav | Mumbai | WA1 1DP | UK | ||
5 | Jamdhade Tush | Deli | S-958 22 | Sweden |
Delete All Records
It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:
DELETE FROM table_name;
The following SQL statement deletes all rows in the "Customers" table, without deleting the table:
Example
DELETE FROM Customers;