DELETE Statement
The DELETE statement removes rows from a table based on a condition. If no WHERE clause is specified, all rows are removed.
Syntax
DELETE FROM table_name
[WHERE condition];
Key Points
- The
FROMkeyword is optional in many SQL dialects. - A
WHEREclause limits which rows are deleted. - Use
TOP (n)orLIMIT n(depending on the RDBMS) to delete a subset. - Deleting without
WHEREpermanently removes all rows. Use with caution.
Examples
1. Delete specific rows
DELETE FROM Employees
WHERE Department = 'Sales' AND HireDate < '2020-01-01';
2. Delete all rows (truncate equivalent)
DELETE FROM Logs;
3. Delete with LIMIT (MySQL)
DELETE FROM Sessions
WHERE LastActive < NOW() - INTERVAL 30 DAY
LIMIT 1000;