TRUNCATE (Truncate Table)

Last updated: 2026-11-04

TRUNCATE (Truncate Table)

TRUNCATE empties a table in one shot, much faster than row-by-row DELETE. It rewrites the table's data file and reclaims all the space at once, so it leaves no dead tuples behind for VACUUM to clean up. It can also truncate tables referenced by foreign keys, or reset the identity sequence with RESTART IDENTITY.

Kindcommand
Example LanguageSQL

📝 Syntax

TRUNCATE [TABLE] [ONLY] <table> [, ...]
[RESTART IDENTITY | CONTINUE IDENTITY]
[CASCADE | RESTRICT]

⚙️ Parameters

RESTART IDENTITYResets the associated identity/serial sequence
CONTINUE IDENTITYKeeps the sequence going (the default)
CASCADEAlso truncates tables referencing this one
RESTRICTRefuses when a foreign key references the table (the default)

Returns:No return value. After the statement succeeds the table is empty.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

DROP TABLE
CREATE TABLE
INSERT 0 3
TRUNCATE TABLE
rows_left
---------
        0

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QWhat exactly separates TRUNCATE from DELETE?
ATRUNCATE is faster (it rewrites the file instead of marking rows), fires no row-level DELETE triggers, returns space immediately, and can reset sequences. DELETE runs row by row, fires triggers, and leaves dead tuples for VACUUM.
QDoes the identity counter restart after TRUNCATE?
ANot by default — the sequence keeps counting up. Add RESTART IDENTITY to reset it to the start value.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏