DELETE vs TRUNCATE vs DROP in SQL
Surgery, fast reset, structure removal
DELETE removes selected rows transactionally (logged, rollback-able, triggers fire) — needs WHERE or it empties the table. TRUNCATE empties fast via page deallocation (resets sequences, minimal logging, restricted rollback in some engines). DROP removes the table definition itself. Recovery story decides.
DELETE is surgery
Filtered, logged, transactional, triggers fire. Preview the WHERE as SELECT first.
TRUNCATE is reset
Deallocates pages — fast full empty, resets sequences, minimal logging.
DROP is removal
Definition, indexes, constraints gone. Needs backup + recreate script.
Recovery decides
Need undo → DELETE. Staging reset → TRUNCATE. Structure gone → DROP.
1DELETE FROM employees WHERE id = 99; -- 0 rows (no id 99), table unchanged2TRUNCATE TABLE staging; -- fast full reset
| command | meaning |
|---|---|
| DELETE | selective, logged, transactional |
| TRUNCATE | full, fast, sequence-resetting |
| DROP | structure gone |
DELETE filters like SELECT and can ROLLBACK. TRUNCATE skips row-by-row logging for speed. DROP deletes the grid itself, not just its rows.
Guarded DELETE
One predicate, one transaction, verifiable.
1BEGIN;2DELETE FROM employees WHERE id = 99;3-- check row count...4COMMIT;
| result |
|---|
| 0 rows — id 99 absent, table unchanged |
Reset vs removal
Staging reset keeps structure; DROP needs rebuild.
1TRUNCATE TABLE staging;2-- vs3-- DROP TABLE staging;
| command | effect |
|---|---|
| TRUNCATE | rows gone, structure kept |
| DROP | structure gone |
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.