SQL DELETE

The SQL DELETE Statement

The DELETE statement is used to delete existing records in a table.

Warning: 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!


Syntax

DELETE FROM table_name
WHERE condition;

Demo Database

Below is a selection from the Customers table:

Customers Table:

CustomerID CustomerName Country
1 Alfreds Futterkiste Germany
2 Ana Trujillo Emparedados Mexico
3 Antonio Moreno Taquería Mexico

Example 1: Delete a Single Record

The following SQL statement deletes the customer "Alfreds Futterkiste" from the Customers table:

DELETE Example

DELETE FROM Customers
WHERE CustomerName = 'Alfreds Futterkiste';

Example 2: Delete All Records

It is possible to delete all rows in a table without deleting the table itself. This means that the table structure, attributes, and indexes will be intact.

The following SQL statement deletes all rows in the Customers table, without deleting the table:

Delete All Records Example

-- Be very careful with this command!
DELETE FROM Customers;

A faster alternative for deleting all data is the TRUNCATE TABLE command, though it works slightly differently and cannot be rolled back in some database systems.