What is the difference between TRUNCATE and DELETE?
Short answer: And does not log individual row deletions.
Explain a bit more
Cannot be rolled back (in most databases). And does not log individual row deletions. Cannot be rolled back (in most databases). nd does not log individual row deletions. Cannot be rolled back (in most databases). Resets auto-increment counters. DELETE: Deletes rows based on a condition, and can be rolled back (if using transactions). Slower compared to TRUNCATE. DELETE FROM Employees WHERE Age < 18; -- Deletes only specific rows TRUNCATE TABLE Employees; -- Deletes all rows nd does not log individual row deletions. Cannot be rolled back (in most databases). Resets auto-increment counters. DELETE: Deletes rows based on a condition, and can be rolled back (if using transactions). Slower compared to TRUNCATE.
Example code
DELETE FROM Employees WHERE Age < 18; -- Deletes only specific rows TRUNCATE TABLE Employees; -- Deletes all rows
Real-world example (ShopNest)
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png