What is the difference between DELETE, TRUNCATE and DROP?
IntermediateConceptMySQL
Answer
Short answer
DELETE removes rows (all, or those matching WHERE) one by one, can be rolled back and fires triggers. TRUNCATE empties the whole table instantly by recreating it — much faster, resets auto-increment, can't use WHERE, and in MySQL can't be rolled back. DROP deletes the table itself — structure and data.
Comparison
| DELETE | TRUNCATE | DROP | |
|---|---|---|---|
| Removes | Some or all rows | All rows | The whole table |
| WHERE clause | ✅ | ❌ | ❌ |
| Speed on big tables | Slow | Very fast | Very fast |
| Rollback (MySQL) | ✅ inside a transaction | ❌ (implicit commit) | ❌ |
| Resets AUTO_INCREMENT | No | Yes | — |
| Table still exists | Yes | Yes | No |
Examples
DELETE FROM sessions WHERE created_at < NOW() - INTERVAL 30 DAY;
TRUNCATE TABLE staging_import;
DROP TABLE old_reports;
Production tips
- Deleting millions of rows in one
DELETElocks rows and bloats the undo log — delete in batches (LIMIT 10000in a loop). - Take a backup (or at least
CREATE TABLE x_backup AS SELECT ...) before TRUNCATE/DROP.
What to say in the interview
"DELETE is row-by-row DML that supports WHERE and rollback; TRUNCATE quickly empties a table and resets auto-increment but is DDL; DROP removes the table entirely. For big purges I delete in batches to avoid long locks."
More on MySQL
How do you set up MySQL and log in to it?BeginnerHow do you create a database, a table and see data in MySQL?BeginnerHow do you create a MySQL user for an application and give it permissions?BeginnerHow do you back up and restore a MySQL database?BeginnerWhat is a relational database?BeginnerWhat is the difference between a database, a table, a row and a column?Beginner