DROP_TABLE(7pg15)

πŸ“¦ version 15.19, in opensuse-leap 16.0

πŸ’… DROP TABLE

okay bestie, so this one's from the PostgreSQL 15.19 docs and it's literally the "bye forever" button for tables. Buckle up, it's giving destructive main character energy πŸ”₯


✨ SYNOPSIS ✨

DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

🌸 DESCRIPTION 🌸

DROP TABLE removes tables from the database. That's it, that's the vibe. πŸ’€

But ngl, not just anyone can do it β€” only the table owner, the schema owner, and superuser can drop a table. So if you're getting told no, it's not personal, it's permissions.

And listen 🫢 β€” if you just wanna empty a table of rows without destroying the table itself, do not drop it. Use DELETE or TRUNCATE instead. Dropping is the "burn the whole house down" option, those are the "just clear out the closet" option.

Here's the tea on what gets cleaned up automatically: DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table. Zero effort needed, they go down with the ship. 🚒

BUT 😭 β€” if you're dropping a table that's referenced by a view or a foreign-key constraint of another table, you must specify CASCADE. And the way CASCADE behaves differs by case, so pay attention:

  • in the view case, it removes the dependent view entirely
  • in the foreign-key case, it only removes the foreign-key constraint, not the other table entirely

iykyk πŸ’…


πŸŽ€ PARAMETERS πŸŽ€

  • IF EXISTS β€” do not throw an error if the table does not exist. A notice is issued in this case. Basically "no drama if it's already gone" ✨
  • name β€” the name (optionally schema-qualified) of the table to drop. Yes bestie, schema-qualified is allowed πŸ’–
  • CASCADE β€” automatically drop objects that depend on the table (such as views), and in turn all objects that depend on those objects (see Section 5.14). It's giving domino effect πŸ”₯
  • RESTRICT β€” refuse to drop the table if any objects depend on it. This is the default, so like... it's already on your side, protecting you πŸ™ˆ
⚠️ real talk: CASCADE is a whole chain reaction. It doesn't just take out the first layer of dependents, it goes after everything that depends on those things too. Read Section 5.14 before you get bold, fr fr.

🌈 EXAMPLES 🌈

To destroy two tables, films and distributors:

DROP TABLE films, distributors;

two tables, one command, absolutely ate πŸ‘‘


πŸ¦‹ COMPATIBILITY πŸ¦‹

This command conforms to the SQL standard β€” with two little caveats:

  • the standard only allows one table to be dropped per command
  • apart from the IF EXISTS option, which is a PostgreSQL extension

so like, mostly iconic, slightly extra πŸ’…


⭐ SEE ALSO ⭐


and that's the whole page, bestie πŸ§šπŸ’œ β€” brought to you by PostgreSQL 15.19, dated 2026, aka the <rainbow>DROP TABLE(7)</rainbow> manual page. now go forth and drop responsibly, mwah πŸŽ€

πŸ“¦ where this page comes from