TRUNCATE TABLE is an SQL statement that removes every row from a table in a single operation while keeping the table definition, columns, indexes, constraints and permissions intact. In SQL, it is the fastest standard way to empty a table, because the database engine deallocates whole data pages instead of deleting and logging each row individually.
The statement is often shortened to TRUNCATE and was added to the SQL standard in SQL:2008, although products such as Oracle Database, Microsoft SQL Server, MySQL and PostgreSQL supported it long before. Many systems classify it as DDL rather than DML, which explains much of its distinctive behavior.
How TRUNCATE TABLE empties a table
Instead of scanning rows, TRUNCATE TABLE releases the storage that holds the table data and resets the table to an empty state. In SQL Server, the engine deallocates data pages and extents and logs only those deallocations; in PostgreSQL, it creates a new empty data file for the table and its indexes and removes the old files at commit; in MySQL with InnoDB, it is implemented as a drop and re-create of the table.
Because the work depends on the number of allocated pages rather than the number of rows, truncating a table with one billion rows typically takes about as long as truncating one with a thousand rows. The basic syntax is TRUNCATE TABLE table_name;, and several systems accept optional clauses.
The table below lists the most common options and their effect.
| Option | Supported by | Effect |
|---|---|---|
RESTART IDENTITY | PostgreSQL, SQL standard | Resets identity and owned sequences to their start value |
CONTINUE IDENTITY | PostgreSQL, SQL standard | Keeps current sequence values (default in PostgreSQL) |
CASCADE | PostgreSQL, Oracle (12c and later) | Also truncates tables that reference the target through foreign keys |
WITH (PARTITIONS ...) | SQL Server 2016 and later | Truncates only the listed partitions |
REUSE STORAGE | Oracle Database | Keeps allocated extents for later inserts |
TRUNCATE TABLE compared with DELETE and DROP TABLE
The three statements remove data at different levels: rows, contents or the whole object. DELETE without a WHERE clause removes rows one by one and fires row-level triggers; TRUNCATE TABLE removes all contents at once; DROP TABLE removes the table definition together with its data.
The following comparison shows how the statements differ in behavior that matters in production.
| Property | DELETE | TRUNCATE TABLE | DROP TABLE |
|---|---|---|---|
| Statement category | DML | DDL in most systems | DDL |
| WHERE clause | Supported | Not supported | Not applicable |
| Logging | Every row logged | Page deallocation logged | Object removal logged |
| Row-level DELETE triggers | Fired | Not fired | Not fired |
| Identity counter | Kept | Usually reset | Removed with the table |
| Table structure afterward | Kept | Kept | Removed |
| Speed on large tables | Slow, proportional to rows | Fast, nearly constant | Fast |
A practical consequence is that DELETE can be filtered and audited row by row, whereas TRUNCATE TABLE is an all-or-nothing operation intended for staging, scratch and reloadable tables.
Transactions, rollback and locking
Whether TRUNCATE TABLE can be rolled back depends on the database product. A widespread misconception claims that it can never be undone, which is true only in systems that issue an implicit commit for DDL statements.
| Database system | Rollback possible | Notes |
|---|---|---|
| PostgreSQL | Yes | Fully transactional, but not MVCC-safe for concurrent snapshots |
| Microsoft SQL Server | Yes | Rollback works inside an explicit transaction |
| Oracle Database | No | Implicit commit before and after the statement |
| MySQL | No | Causes an implicit commit |
| SQLite | Not applicable | No TRUNCATE; DELETE without WHERE uses a truncate optimization |
TRUNCATE TABLE also requires a strong exclusive table lock: an ACCESS EXCLUSIVE lock in PostgreSQL and a schema modification lock in SQL Server. While the statement waits for or holds that lock, all reads and writes on the table are blocked, so a long-running query on the table can stall the truncate and every session queued behind it.
Restrictions and required permissions
Most systems refuse to truncate a table referenced by a foreign key from another table, even when the referencing table is empty, because the engine does not check individual rows. The usual remedies are to truncate the child and parent together, use CASCADE where supported, or temporarily drop the constraint.
- In SQL Server, tables that participate in indexed views, transactional replication or change data capture cannot be truncated.
- The required privilege is often broader than for DELETE: SQL Server requires ALTER permission on the table, while PostgreSQL has a dedicated TRUNCATE privilege.
- Statement-level
ON TRUNCATEtriggers exist in PostgreSQL, but row-level DELETE triggers never fire, so audit logic built on them is silently bypassed. - Logical replication and change capture tools may handle truncation differently from deletes, so downstream replicas must be checked.
When to use TRUNCATE TABLE
TRUNCATE TABLE is the right choice when all rows must go and no per-row logic is needed. The decision table below summarizes typical situations.
| Situation | Recommended statement | Reason |
|---|---|---|
| Reloading a staging table in an ETL job | TRUNCATE TABLE | Fast, minimal logging, resets storage |
| Removing rows older than 90 days | DELETE with WHERE | Only a subset must be removed |
| Clearing an audited business table | DELETE | Triggers and audit records must fire |
| Retiring a table permanently | DROP TABLE | The structure is no longer needed |
| Emptying one month of a partitioned table | Partition truncate or drop | Affects one partition only |
Because the statement is fast and irreversible in several products, teams commonly restrict the privilege to deployment and ETL accounts and require a verified backup before running it on any table that holds business data.
The idea in brief
Imagine a filing cabinet full of folders. DELETE takes out the folders one at a time and writes down each one it removes. TRUNCATE TABLE swaps the drawer for an empty one, keeping the cabinet and its labels exactly as they were.
That makes it very fast for emptying large tables. The catch is that it removes everything, skips per-row checks and, in some databases, cannot be undone once it runs.
A practical scenario
A retail analytics team loads about 25 million sales rows every night into a staging table before transforming them into reporting tables. The original job began with DELETE FROM stage_sales;, which took roughly 40 minutes, generated tens of gigabytes of transaction log and sometimes filled the log disk.
After switching to TRUNCATE TABLE stage_sales;, the clearing step finished in under two seconds and the log growth practically disappeared. The team also moved the statement to a dedicated ETL account, because the job had previously run with broad administrator rights.
One lesson came during testing on SQL Server: the truncate failed because a reporting table had a foreign key pointing to the staging table. The team removed that unnecessary constraint, and the nightly load now completes about 45 minutes earlier.