Skip to content
We areTOP 1%

What is the difference between DELETE, TRUNCATE and DROP?

EasyConceptDBMS Fundamentals
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

DELETE removes selected rows, TRUNCATE removes all rows but keeps the empty table, and DROP removes the whole table, including its structure, indexes and constraints.

  • DELETE is DML: it accepts a WHERE clause, removes rows one at a time, fires delete triggers and can be rolled back.
  • TRUNCATE is DDL: it deallocates the data pages at once, so it is much faster on large tables. It takes no WHERE clause, does not fire delete triggers, and resets the auto-increment counter in MySQL and SQL Server.
  • DROP is DDL: afterwards, any query on the table fails because the table no longer exists.
  • Rolling back TRUNCATE or DROP works inside a transaction in PostgreSQL and SQL Server, but not in MySQL or Oracle, where DDL commits implicitly.

Example: For an orders table with 3 rows:

DELETE FROM orders WHERE id = 2;  -- 2 rows remain
TRUNCATE TABLE orders;            -- 0 rows, table still exists
DROP TABLE orders;                -- the table itself is gone

More in DBMS Fundamentals

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account