Back to SQL Notes
Topic #76

TRUNCATE TABLE in SQL

TRUNCATE TABLE removes all rows from a table instantly, but keeps the table structure intact — ready to insert into again.

Syntax

TRUNCATE TABLE table_name;

Example

TRUNCATE TABLE staging_orders;

Every row in staging_orders is gone; the table, its columns, indexes, and constraints remain.

TRUNCATE vs DELETE — The Classic Interview Comparison

TRUNCATEDELETE
RemovesAll rows onlyRows matching WHERE (or all, if no WHERE)
WHERE clause?Not allowedAllowed
Speed on large tablesMuch faster — deallocates data pagesSlower — removes row by row, logged individually
Auto-increment counterResets to start (in most databases)Keeps counting from where it left off
TriggersUsually does NOT fire DELETE triggersFires DELETE triggers
Transactional?PostgreSQL/SQL Server: yes. MySQL: implicit commit, harder to roll backFully transactional (COMMIT/ROLLBACK)

Practical Use Case

Clearing a staging table between nightly ETL loads, or resetting a test/demo table — anywhere you want "empty, like new" rather than selectively removing rows.

Common Mistakes

  • Trying to add a WHERE clause to TRUNCATE — it doesn't support one; use DELETE if you need conditional removal
  • Assuming TRUNCATE is always safely reversible with ROLLBACK — in MySQL, it behaves like DDL and commits immediately
  • Truncating a table that a foreign key still references — most databases will block this unless the constraint allows it

Interview Relevance

"Explain the difference between DELETE, TRUNCATE, and DROP" is one of the most frequently asked SQL basics questions. Structure your answer around: what's removed, whether WHERE is allowed, and transactional behavior — exactly the table above.

Practice Question

You need to remove only orders placed before 2023 from a table, not all of them. Should you use TRUNCATE or DELETE? Why?

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

TRUNCATE TABLE in SQL – FAQs

Quick answers about learning TRUNCATE TABLE in SQL in SQL.

This free note from Coding Now Tech Institute explains TRUNCATE TABLE in SQL in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including TRUNCATE TABLE in SQL, is 100% free with no signup required.
With focused practice, most students grasp TRUNCATE TABLE in SQL in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now