SQL > Data Definition Language (DDL) > Truncate Table Statement

Sometimes we wish to get rid of all the data in a table. One way of doing this is with DROP TABLE, which we saw in the last section. But what if we wish to simply delete the data but not the table itself? For this, we can use the TRUNCATE TABLE command.

Key Takeaway: TRUNCATE TABLE deletes all rows in a table without removing the table structure, and is significantly faster than DELETE FROM because it does not log individual row deletions. However, it cannot be used when FOREIGN KEY constraints would be violated.

The syntax for TRUNCATE TABLE is,

TRUNCATE TABLE "table_name";

So, if we wanted to truncate the Customer table that we created in SQL CREATE TABLE, we simply type,

TRUNCATE TABLE Customer;

Please note that the TRUNCATE TABLE command cannot delete any rows of data that would violate FOREIGN KEY or other constraints.

Truncate Table vs Delete

Functionally, the following two SQL statements are equivalent. Both will delete all rows from the Customer table:

TRUNCATE TABLE Customer;

and

DELETE FROM Customer;

The difference between the two is in the amount of system resources consumed. DELETE FROM requires more system resources, and hence takes longer to complete, because the RDBMS has to record all changes one row at a time in the transaction log, while a TRUNCATE TABLE operation does not record the change one row at a time, so it can be completed quicker.

Frequently Asked Questions

What does SQL TRUNCATE TABLE do?
TRUNCATE TABLE removes all rows from a table instantly while keeping the table definition — columns, indexes, and constraints — intact. It is the fastest way to empty a table.
What is the difference between TRUNCATE TABLE and DELETE FROM?
Both remove all rows when no WHERE clause is used. However, TRUNCATE TABLE is faster because it does not write individual row deletions to the transaction log, whereas DELETE FROM logs each deleted row individually.
Can TRUNCATE TABLE be rolled back?
In most relational databases TRUNCATE is a DDL operation and performs an implicit commit, making rollback impossible. PostgreSQL is a notable exception: it supports TRUNCATE inside a transaction that can be rolled back.
Can I use TRUNCATE when foreign key constraints exist?
No. TRUNCATE TABLE will fail if any rows being deleted are referenced by a FOREIGN KEY constraint in another table. You must remove or disable the constraint, or delete the child rows first.

Next: SQL USE

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact