DELETE — Removing Rows in SQL
Delete rows, not tables — WHERE is mandatory thinking
DELETE removes whole rows matching a WHERE condition. Without WHERE it empties the entire table (still logging every removed row). Related sibling: TRUNCATE empties a table instantly without row-by-row logging, and DROP TABLE deletes the table structure itself. As with UPDATE, preview the condition with SELECT first.
Target rows with WHERE
DELETE FROM employees WHERE department = 'Marketing' — the condition grammar is the same as in SELECT.
Preview the hit list
Run the identical condition as a SELECT first — you cannot undelete what you never backed up.
Whole rows go
DELETE removes entire rows; you cannot delete "a column's value" — set it to NULL instead.
Know the no-WHERE version
DELETE FROM employees empties the table, row by row, logged. TRUNCATE does it instantly but cannot be filtered.
Mind foreign keys
Deleting a referenced parent may block (RESTRICT) or cascade (CASCADE) — know which your schema chose.
1DELETE FROM employees2WHERE department = 'Marketing';
| id | name | department | salary | age |
|---|---|---|---|---|
| 1 | Alice | Engineering | 85000 | 29 |
| 2 | Bob | Sales | 52000 | 35 |
| 3 | Cynthia | Engineering | 91000 | 41 |
| 5 | Elena | Sales | 58000 | 26 |
| 6 | Farid | Engineering | 73000 | 33 |
David’s Marketing row is removed; the remaining five rows shift up. Run the visualization and watch the doomed row dissolve while survivors close the gap.
Delete a group
Remove every Marketing row.
1DELETE FROM employees2WHERE department = 'Marketing';
| id | name | department | salary | age |
|---|---|---|---|---|
| 1 | Alice | Engineering | 85000 | 29 |
| 2 | Bob | Sales | 52000 | 35 |
| 3 | Cynthia | Engineering | 91000 | 41 |
| 5 | Elena | Sales | 58000 | 26 |
| 6 | Farid | Engineering | 73000 | 33 |
Delete one by key
The safest delete — a unique key.
1DELETE FROM employees WHERE id = 4;
| id | name | department | salary | age |
|---|---|---|---|---|
| 1 | Alice | Engineering | 85000 | 29 |
| 2 | Bob | Sales | 52000 | 35 |
| 3 | Cynthia | Engineering | 91000 | 41 |
| 5 | Elena | Sales | 58000 | 26 |
| 6 | Farid | Engineering | 73000 | 33 |
The empty table
No WHERE = every row goes.
1DELETE FROM employees;2-- table now has 0 rows (structure remains)
Soft delete instead
Production often never really deletes.
1UPDATE employees2SET deleted_at = NOW()3WHERE id = 4;4-- readers add: WHERE deleted_at IS NULL
| id | name | department | salary | age |
|---|---|---|---|---|
| 1 | Alice | Engineering | 85000 | 29 |
| 2 | Bob | Sales | 52000 | 35 |
| 3 | Cynthia | Engineering | 91000 | 41 |
| 5 | Elena | Sales | 58000 | 26 |
| 6 | Farid | Engineering | 73000 | 33 |
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.