Lesson 15 of 30
50%
DELETE
DELETE removes rows. The table stays. The matching rows vanish.
There is no recycle bin. Be slow and careful.
Delete matching rows
sql
Result
Query OK, 1 row affected
Always use WHERE
DELETE FROM students; would wipe the whole table.
MySQL can be set to block that, but do not rely on luck.
sql
Result
Not run. This would delete every row.
DELETE vs DROP
1
DELETE removes rows
2
TRUNCATE is a fast empty of all rows
3
DROP TABLE removes the table itself
Practice safely
SELECT the rows first. Then DELETE with the same WHERE.
sql
Result
| id | name | age | city |
|---|---|---|---|
| 5 | Nia | 10 | Unknown |
1 row
Query OK, 1 row affected
Tip: On a real database, take a backup before a big DELETE.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.