What are the differences between DELETE, TRUNCATE, and DROP in terms of transaction logging, speed, and rollback ability?
Last updated
All three remove data, but at different levels: DELETE removes rows (DML), TRUNCATE empties a whole table fast (usually DDL), and DROP removes the table object itself.
DELETE:Row-by-row, honors
WHEREand fires triggers.Fully logged per row, so slower on large tables but fully rollback-able in a transaction.
TRUNCATE:Deallocates data pages instead of logging each row, so it's very fast.
No
WHERE, typically resets identity/auto-increment, and doesn't fire row triggers.Rollback depends on the engine: recoverable in a transaction on SQL Server/PostgreSQL, but implicitly commits in MySQL/Oracle.
DROP:Removes the table structure, data, indexes, and constraints entirely.
DDL; generally cannot be rolled back once committed (auto-commits in many engines).
- https://snehagupta-contact.medium.com/the-difference-between-delete-drop-and-truncate-in-sql-fd5d07a88acb
- https://learn.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-ver17
- https://architecture-performance.fr/en/blog/rollback-delete-vs-truncate-vs-drop-in-several-rdbms
- https://medium.com/@utsavanand1/performance-differences-between-truncate-and-delete-in-sql-server-07a534078b52
- https://www.postgresql.org/docs/current/sql-truncate.html
- https://dev.to/chat2db/differences-between-drop-delete-and-truncate-in-sql-5983
- https://learn.microsoft.com/en-us/sql/t-sql/statements/drop-table-transact-sql?view=sql-server-ver17
- https://www.youtube.com/watch?v=J9DIT2wKdqE