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.
| Kind | command |
|---|---|
| Example Language | SQL |
📝 Syntax
DROP TABLE [IF EXISTS] <table> [, ...] [CASCADE | RESTRICT]
⚙️ Parameters
| IF EXISTS | Do not raise an error when the table is missing |
|---|---|
| CASCADE | Also drop objects that depend on the table |
| RESTRICT | Refuse 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
- The default is RESTRICT: with dependents present you get cannot drop table ... because other objects depend on it.
- CASCADE also removes dependent objects such as views built on the table — check what depends on it first.
- Dropping a table takes its identity sequence, indexes, and triggers with it.
- DROP TABLE IF EXISTS does not fail when the table is missing, which makes it safe in repeatable scripts.
- To empty a table but keep its structure, use TRUNCATE instead of DROP TABLE.
💡 Related Cases
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.