SQL DELETE Statement
The DELETE
statement in SQL is used to remove rows from a table. It's a powerful command, but use it cautiously because deleting data is typically irreversible (unless you have backups).
DELETE: Definition and Usage
DELETE
removes rows from a table based on the conditions you specify in the WHERE
clause. The WHERE
clause is absolutely critical; omitting it will delete *all* rows in the table. This is often undesirable and can result in a significant loss of data.
Syntax
Syntax
DELETE FROM table_name
WHERE condition;
Example
Deleting a Specific Row
This example deletes the customer "Alfreds Futterkiste" from the 'Customers' table. (Assumes a 'Customers' table with a 'CustomerName' column).
Syntax
DELETE FROM Customers
WHERE CustomerName = 'Alfreds Futterkiste';
Output
(The row representing Alfreds Futterkiste is deleted from the Customers table.)
Deleting All Rows (Caution!)
This example shows how to delete *all* rows from the 'Customers' table. The table structure remains, but all data is gone. Use this with extreme care!
Syntax
DELETE FROM Customers;
Output
(All rows are deleted from the Customers table. The table structure remains intact.)