What does the TRUNCATE command do?
The TRUNCATE command in SQL is used to completely remove every record from a table, but it doesn't remove the table itself or its structure.
Example:
sql
TRUNCATE TABLE Employees;What's worth knowing:
- Removes all the data at once, faster than
DELETE, since it doesn't check each record individually. - Keeps the table's structure, the fields, data types, and constraints stay.
- Doesn't support
WHERE, you can't remove just part of the records. - Auto-increment counters are often reset to their starting value (e.g. ID).
- A rollback isn't always possible, in some DBMSs
TRUNCATEcan't be undone withROLLBACK.
Put simply,
TRUNCATEis a fast way to completely clear a table, leaving it ready for new data.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.