TRUNCATE TABLE
What is TRUNCATE TABLE?
TRUNCATE TABLE removes all rows from a table in one fast operation. Unlike DELETE, it does not scan every row individually, making it significantly faster for large tables.
The table structure, columns, indexes, and constraints remain intact. Only the data is removed.
Syntax
TRUNCATE TABLE table_name;To truncate multiple tables at once:
TRUNCATE TABLE table1, table2;To also reset identity/serial columns:
TRUNCATE TABLE table_name RESTART IDENTITY;When to Use
- Clearing staging or temporary tables before loading new data
- Resetting a table in a test environment
- Removing all data faster than a
DELETEwithout a WHERE clause
Key Points
- No WHERE Clause — TRUNCATE always removes all rows. Use DELETE if you need to remove a subset.
- Faster Than DELETE — TRUNCATE does not generate individual row-deletion logs, so it is much faster on large tables.
- RESTART IDENTITY — Resets auto-increment (SERIAL/BIGSERIAL) counters back to their initial value.
- CASCADE — TRUNCATE TABLE ... CASCADE also truncates tables with foreign-key references to the target table.
- Not Trigger-Friendly — TRUNCATE fires BEFORE TRUNCATE and AFTER TRUNCATE triggers, not per-row DELETE triggers.
Guided Practice
Solve the challenge below. Use hints when stuck and check your answer for instant feedback.
TRUNCATE TABLE Challenge
Write a query that solve this task: remove all rows from the orders table.
Expected result
All rows in orders are removed. The table structure remains.
Hidden checks
- Returned rows and values
- Output columns and result shape
- Final database state after the query runs
Lesson guidance
What is TRUNCATE TABLE?
Press Run to execute the query once the engine is ready.
More Examples
Truncate and restart identity
Clear all data and reset the auto-increment counter.
Press Run to execute the query once the engine is ready.
Truncate multiple tables with CASCADE
Clear data from enrollments and related referenced tables.
Press Run to execute the query once the engine is ready.