Safe deletion
- SQL course
- Beginner
- Lesson 87/115
- 4 min
Learn ways to avoid accidental deletion.
DELETE vs TRUNCATE
TRUNCATE empties a table quickly. Unlike DELETE it does not go row by row; it drops whole pages at once.
TRUNCATE TABLE products;This query empties the products table instantly.
DELETE vs TRUNCATE — details
TRUNCATE usually cannot be rolled back and resets auto-increment ids. DELETE is slower but can be rolled back inside a transaction.
Practice DELETE vs TRUNCATE
Delete the row with id=4 from products.
Starter code
-- delete row
DELETE FROM products
WHERESample solution
DELETE FROM products
WHERE id = 4Expected output
1 satır silindi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Fast empty
TRUNCATE ____ products;
TRUNCATE TABLE products;
Explanation: TRUNCATE TABLE deletes every row at once, faster than DELETE.
2 Safe deletion: match the terms
| Term | Meaning |
|---|---|
TRUNCATE |
fast delete |
DELETE |
row delete |
DROP |
drop table |
WHERE |
condition |
3 Which empties a table faster?
- DROP
- TRUNCATE Correct answer
- DELETE
- ALTER
Explanation: TRUNCATE is faster than DELETE.