Skip to main content

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:

  1. Removes all the data at once, faster than DELETE, since it doesn't check each record individually.
  2. Keeps the table's structure, the fields, data types, and constraints stay.
  3. Doesn't support WHERE, you can't remove just part of the records.
  4. Auto-increment counters are often reset to their starting value (e.g. ID).
  5. A rollback isn't always possible, in some DBMSs TRUNCATE can't be undone with ROLLBACK.

Put simply, TRUNCATE is a fast way to completely clear a table, leaving it ready for new data.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.