CodeBlanks Logo Icon CodeBlanks

DELETE vs TRUNCATE

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

query.sql
-- delete row
DELETE FROM products
WHERE

Sample solution

query.sql
DELETE FROM products
WHERE id = 5

Expected 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

Question
DELETE ____ products;
Answer
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.

All lessons in Beginner