SQL from Zero › Module 3: DML: filling and changing data
Removing rows with DELETE
Remove the rows you don't need, and only those.
Lesson 15 of 33 · about 10 minutes
Video: Clearing the shelf, carefullyThe narrated video for this lesson is coming soon. The lesson below covers the same ideas.
The lesson
DELETE removes whole rows from a table.
DELETE FROM orders
WHERE status = 'cancelled';
Just like UPDATE, the WHERE decides which rows are affected, and just like UPDATE, forgetting it is a disaster: DELETE FROM orders; removes every order. Use the same habit: SELECT first, then DELETE.
DELETE vs DROP. These are easy to mix up:
| Command | Family | What goes | What stays |
|---|---|---|---|
DELETE FROM books WHERE ... | DML | The matching rows | The table and other rows |
DELETE FROM books | DML | Every row | The empty table |
DROP TABLE books | DDL | The table and all rows | Nothing |
At many companies, important rows are never deleted at all. Instead a column like is_active is set to 0 with an UPDATE. This is called a soft delete, and it means mistakes can be undone and history is kept.
Key ideas
- DELETE FROM table WHERE condition removes matching rows.
- Without WHERE, DELETE removes every row. Check with SELECT first.
- DELETE removes rows; DROP TABLE removes the whole table. Many teams prefer soft deletes.
Practise
Loading practice…