Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Compare TRUNCATE, DELETE without WHERE, and DROP TABLE: what each removes, locking, transactions, triggers, identity values and foreign keys, in PostgreSQL and MySQL.

DELETE without WHERE removes rows one by one, fires row triggers, is fully transactional and leaves dead rows for VACUUM in PostgreSQL or purge in InnoDB. TRUNCATE empties the table by replacing its storage, which is fast, does not fire DELETE triggers, takes the strongest lock and refuses tables referenced by foreign keys unless CASCADE is used; it is transactional in PostgreSQL but an implicitly committing DDL statement in MySQL. DROP TABLE removes the table itself, with its indexes, grants and dependent objects.

Why this question is asked

All three statements make data go away, so it is easy to treat them as interchangeable until one of them locks a busy table, fails on a foreign key, resets an id sequence that other systems depend on, or cannot be rolled back. Interviewers ask for the comparison because the details differ between PostgreSQL and MySQL, and because it shows whether we know what each statement actually does to storage, locks and transactions. In this answer, we will look at what each statement removes, then compare them on locking, transactions, triggers, identity values and foreign keys in both databases.

1What Each Statement Removes

DELETE FROM orders, with no WHERE clause, removes all rows but keeps the table, its columns, indexes, constraints and permissions. It works row by row, like any DELETE that happens to match everything.

TRUNCATE TABLE orders also removes all rows and keeps the table definition, but it does not visit rows. In PostgreSQL it gives the table a fresh, empty storage file and discards the old one when the transaction commits. In MySQL with InnoDB it effectively drops and recreates the table. That is why it takes about the same time for a hundred rows or a hundred million.

DROP TABLE orders removes the table itself: its definition, data, indexes, triggers, grants and statistics. Afterwards, the name does not exist.

2DELETE: Row by Row, Fully Transactional

Because DELETE processes each row, it behaves like any other data change. It fires row-level DELETE triggers, checks foreign keys for every row, writes undo and redo information, and can be rolled back. Other transactions keep seeing the old rows until we commit, which is normal MVCC behaviour: multi-version concurrency control, where readers see a consistent snapshot while writers change data.

SQL
BEGIN;
DELETE FROM orders; -- DELETE 12000000, minutes, fires triggers per row
SELECT count(*) FROM orders; -- 0 in this transaction, other sessions still see 12000000
ROLLBACK; -- everything is back

The cost of DELETE is that the space is not given back immediately. In PostgreSQL, deleted rows become dead tuples that VACUUM must later clean up, and the table file usually stays the same size. In InnoDB, the purge thread removes delete-marked records in the background. Deleting 12 million rows also generates a large amount of write-ahead log or redo log, which replicas have to replay. And DELETE does not reset identity values: the next insert continues from the last id.

3TRUNCATE: Fast, but With Strong Locks and Different Rules

In PostgreSQL, TRUNCATE takes an ACCESS EXCLUSIVE lock, the strongest lock, which blocks even plain SELECTs on the table until the transaction ends. It is transactional: inside BEGIN it can be rolled back. It does not fire ON DELETE triggers, though PostgreSQL has separate statement-level ON TRUNCATE triggers. One subtle point is that it is not MVCC-safe: a concurrent transaction that took its snapshot earlier but touches the table only afterwards will see it as empty.

In MySQL, TRUNCATE is a DDL statement. It causes an implicit commit, so it cannot be rolled back, it does not fire DELETE triggers, and it needs the DROP privilege. It takes a metadata lock that blocks other access to the table while it runs.

SQL
-- PostgreSQL
BEGIN;
TRUNCATE orders; -- instant
ROLLBACK; -- rows are back
TRUNCATE customers; -- ERROR: cannot truncate a table referenced in a foreign key constraint
TRUNCATE customers CASCADE; -- also truncates orders, which references customers
TRUNCATE orders RESTART IDENTITY; -- also resets the id sequence to its start
-- MySQL
TRUNCATE TABLE customers; -- ERROR 1701 when another table's foreign key references it
TRUNCATE TABLE orders; -- AUTO_INCREMENT starts again at 1

Foreign keys are the most common surprise. Because TRUNCATE does not check rows, it cannot know whether removing customers would leave orders pointing at nothing, so both databases refuse when another table references the one being truncated. PostgreSQL offers CASCADE, which truncates every referencing table too, so we must be sure that is what we want. MySQL has no CASCADE for TRUNCATE; we truncate the child first, or drop the constraint, or use DELETE.

Identity values differ as well. PostgreSQL keeps the sequence going by default, CONTINUE IDENTITY, and resets it only with RESTART IDENTITY. MySQL always resets AUTO_INCREMENT on TRUNCATE.

4DROP TABLE: Removing the Table Itself

DROP TABLE removes everything about the table. Indexes, triggers, constraints defined on it and permissions disappear with it. Objects that depend on it, such as views or foreign keys in other tables, block the drop in PostgreSQL unless we add CASCADE, which then drops the views and removes the referencing constraints, but not the referencing tables. In MySQL, dropping a table referenced by a foreign key fails unless the constraint is dropped first or foreign key checks are disabled.

In MySQL, DROP is DDL with an implicit commit, so there is no undo except a backup or point-in-time recovery. PostgreSQL is a little more forgiving: DDL is transactional, so a DROP inside an open transaction can still be rolled back before COMMIT. After commit, in both databases, recovery means a backup.

5Side by Side

The table below puts the main differences together, so we can choose by what we need: DELETE when we need row semantics or a WHERE clause, TRUNCATE to empty a table quickly when nothing else is using it, DROP when the table itself should go.

DELETE vs TRUNCATE vs DROP
AspectDELETE (no WHERE)TRUNCATEDROP TABLE
Removesrowsall rows, keeps definitiontable and its objects
Speedproportional to rowsnear constantnear constant
Lock (PostgreSQL)row locks, readers continueACCESS EXCLUSIVEACCESS EXCLUSIVE
Rollback in PostgreSQLyesyesyes, before commit
Rollback in MySQLyesno, implicit commitno, implicit commit
DELETE triggersfired per rownot firedtriggers are dropped
IdentitycontinuesPG: RESTART IDENTITY; MySQL: resetgone
Referenced by FKrows checkedfails; PG allows CASCADEfails or needs CASCADE
Spacedead rows, VACUUM/purgefreed at oncefreed at once

6Follow-up questions

Why is DELETE of all rows sometimes faster than TRUNCATE?

For very small tables. TRUNCATE in PostgreSQL creates new storage files for the table and its indexes and must synchronise that work, which has a fixed cost per table. Deleting ten rows is cheaper than that fixed cost, which matters in test suites that empty many tiny tables.

Can I use TRUNCATE on a table that replicas or CDC tools read?

Usually yes, but check the tool. PostgreSQL logical replication replicates TRUNCATE since version 11, and MySQL writes TRUNCATE to the binary log as a statement. Change data capture tools may emit a special truncate event or none, so downstream systems might not learn that rows disappeared.

How do I empty a huge table without blocking traffic?

TRUNCATE is quick, but it needs an exclusive lock and waits behind every running query on the table. Set a short lock_timeout so it gives up rather than queueing everyone behind it, or swap in an empty copy with a rename. A big DELETE should be done in batches by key range to limit locks, log volume and replication lag.

7Conclusion

In this answer, we compared the three statements. DELETE removes rows one at a time with triggers, foreign key checks and full transactions, and leaves dead rows for VACUUM or purge. TRUNCATE replaces the table's storage almost instantly, skips DELETE triggers, takes the strongest lock, refuses referenced tables unless CASCADE in PostgreSQL, resets identity with RESTART IDENTITY in PostgreSQL and always in MySQL, and is transactional only in PostgreSQL. DROP removes the table and everything attached to it, and after commit only a backup brings it back.

What to say in the interviewAbout 90 seconds aloud

Open with

DELETE without a WHERE removes every row but works row by row. It fires row triggers, checks foreign keys for each row, is fully transactional so I can roll it back, and other sessions keep seeing the old rows until commit.

Then, if they want more

The downside is cost: it writes a lot of log, takes time proportional to the rows, and leaves dead rows that VACUUM cleans up in PostgreSQL or the purge thread in InnoDB. It does not reset the identity. TRUNCATE empties the table by replacing its storage, so it is near instant regardless of size. It does not fire DELETE triggers.

In PostgreSQL it takes an ACCESS EXCLUSIVE lock that blocks even reads, but it is transactional and can be rolled back; in MySQL it is DDL with an implicit commit, so no rollback.

Both refuse to truncate a table referenced by another table's foreign key; PostgreSQL has TRUNCATE CASCADE, which truncates the referencing tables too, and MySQL needs the child handled first. For identity, PostgreSQL continues the sequence unless I say RESTART IDENTITY, while MySQL always resets AUTO_INCREMENT.

DROP TABLE removes the table itself with its indexes, grants and triggers, and dependent views need CASCADE in PostgreSQL. In MySQL it commits immediately, in PostgreSQL it can be rolled back before commit, and after that only a backup brings it back.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Compare TRUNCATE, DELETE without WHERE, and DROP TABLE: what each removes, locking...": https://scrivio-interview-library.netlify.app/databases/sql-fundamentals/718eb57d84/