DROP TABLE (Drop Table)

Last updated: 2026-11-04

DROP TABLE (Drop Table)

DROP TABLE removes a table along with its indexes, constraints, triggers, and all of its data. If a view or another object depends on the table, the default is to refuse the drop with an error; add CASCADE to remove the dependencies too.

Kindcommand
Example LanguageSQL

📝 Syntax

DROP TABLE [IF EXISTS] <table> [, ...] [CASCADE | RESTRICT]

⚙️ Parameters

IF EXISTSDo not raise an error when the table is missing
CASCADEAlso drop objects that depend on the table
RESTRICTRefuse the drop when dependencies exist (the default)

Returns:No return value. Once the statement succeeds the table is gone from the system catalogs.

▶ 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
DROP TABLE
CREATE TABLE
CREATE VIEW
DROP TABLE
dependent_view_dropped
----------------------
true

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QShould I use DROP TABLE or TRUNCATE?
AUse DROP TABLE to remove the structure as well; use TRUNCATE to empty the table but keep it — much faster and without row-level DELETE triggers.
QThe drop fails with other objects depend on it — what now?
ACheck the dependencies first with SELECT * FROM pg_depend. Drop the obsolete views explicitly, or use DROP TABLE ... CASCADE to remove them together.
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%

🙏 帮我们做得更好

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

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