TRUNCATE TABLE is a Data Definition Language (DDL) command that deletes every row in a table without scanning each row individually. Because most engines log only page de-allocations rather than row-level deletes, the operation is much faster and uses far less transaction log space than DELETE. In many systems it resets AUTO_INCREMENT or IDENTITY values and releases the physical storage back to the tablespace. Truncation cannot include a WHERE clause, cannot be used on views, and is blocked when foreign-key references exist unless the dialect supports CASCADE. In PostgreSQL and Oracle, TRUNCATE can run inside a transaction and can be rolled back; in MySQL the statement issues an implicit COMMIT before and after execution. Triggers defined for DELETE events do not fire, but dialect-specific TRUNCATE triggers may. Permissions usually require the ALTER or DROP privilege on the target table.
table_name
(identifier) - Name of the table to truncate. Required.RESTART IDENTITY
(keyword) - Reset sequences associated with the table to their start values (PostgreSQL).CONTINUE IDENTITY
(keyword) - Keep current sequence values (PostgreSQL default).CASCADE
(keyword) - Automatically truncate tables that have foreign-key references to the target table (PostgreSQL, Oracle).RESTRICT
(keyword) - Refuse to truncate if foreign-key references exist (default).DELETE, DROP TABLE, ALTER TABLE, COMMIT, ROLLBACK
SQL:2008
Yes. Because the database de-allocates entire data pages instead of logging each row delete, TRUNCATE is significantly faster and uses far less transaction log space.
It depends on the dialect. MySQL and SQL Server reset the counter automatically. PostgreSQL requires the RESTART IDENTITY option, while Oracle leaves identity values unchanged.
PostgreSQL and Oracle allow rollback if executed inside an explicit transaction. MySQL and older SQL Server versions wrap the command in an implicit COMMIT, so the operation cannot be undone.
No. TRUNCATE is treated as a DDL command, so standard DELETE triggers do not execute. Some databases offer dedicated TRUNCATE triggers that must be created separately.