Loading lessons...
DELETE Statement
DELETE Statement
The DELETE statement removes rows from a table.
Basic syntax
DELETE FROM Customers
WHERE CustomerName = 'Cardinal';
Deletes only the rows that match the WHERE condition.
BE CAREFUL: DELETE without WHERE
DELETE FROM Customers;
Deletes every row in the table. The table structure stays, but it is empty.
Delete all rows (two ways)
DELETE FROM Customers;
or
TRUNCATE TABLE Customers;
DELETEremoves rows one by one.TRUNCATEremoves all rows in one go and is faster.
DELETE does NOT drop the table
After DELETE, the table still exists - only its rows are gone.
The safe pattern
SELECT * FROM Customers WHERE CustomerName = 'Cardinal'; -- check first
DELETE FROM Customers WHERE CustomerName = 'Cardinal';
TL;DR
- DELETE removes rows.
- WHERE decides which rows to remove.
- Without WHERE, all rows are deleted.
- TRUNCATE TABLE empties a table faster.