Both TRUNCATE TABLE and DELETE FROM table (without WHERE) remove all rows from a table, but they behave very differently under the hood. Choosing the right one depends on your needs for performance, rollback capability, and trigger firing.
Key Differences
- Speed: TRUNCATE is much faster because it drops and recreates the table data pages rather than removing rows one by one.
- Auto-increment: TRUNCATE resets the auto-increment counter to 1; DELETE does not.
- Triggers: DELETE fires row-level DELETE triggers; TRUNCATE does not.
- Transactions: DELETE can be rolled back; TRUNCATE is DDL and implicitly commits in most cases.
- Foreign keys: TRUNCATE fails if the table is referenced by a foreign key; DELETE respects FK constraints row by row.
When to Use Each
Use TRUNCATE for resetting lookup tables or clearing test data quickly. Use DELETE when you need rollback safety, need triggers to fire, or have foreign key dependencies.