DELETE vs TRUNCATE
- SQL course
- Beginner
- Lesson 85/115
- 4 min
Learn the difference between DELETE and TRUNCATE.
Delete all rows
Without WHERE, DELETE FROM table removes all rows. The table structure stays; only data goes.
DELETE FROM products;This query removes all rows from products; the table becomes empty.
Rows are deleted from products.
Delete all rows — details
Deleting all rows is risky. A faster alternative is TRUNCATE; but TRUNCATE cannot be rolled back and resets auto-increment ids.
Practice Delete all rows
Delete the row with id=5 from products.
Starter code
-- delete row
DELETE FROM products
WHERESample solution
DELETE FROM products
WHERE id = 5Expected output
1 satır silindi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 DELETE vs TRUNCATE: match the terms
| Term | Meaning |
|---|---|
DELETE |
delete |
WHERE |
condition |
TRUNCATE |
fast delete |
DROP |
drop table |
2 Delete all
DELETE ____ products;
DELETE FROM products;
Explanation: DELETE FROM without WHERE removes every row in the table.
3 What does DELETE FROM table (no WHERE) do?
- Deletes the first row
- Drops the table
- Raises an error
- Deletes all rows Correct answer
Explanation: DELETE without WHERE removes all rows.