DROP_TABLE(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’… DROP TABLE โ€” the manual page, but make it a group chat

ok so bestie, welcome to DROP_TABLE from the PostgreSQL 18.6 docs. it's giving "the nuclear option, but make it cute". let's get into it ๐ŸŽ€


โœจ NAME โœจ

DROP_TABLE โ€” remove a table ๐Ÿ’€ (yes. gone. bye.)


โœจ SYNOPSIS โœจ

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

look at her. short. powerful. terrifying. iconic ๐ŸŒˆ


โœจ DESCRIPTION โœจ

okay so DROP TABLE removes tables from the database. periodt. ๐Ÿ’…

but hold up โ€” not just anyone can do this. only the table owner, the schema owner, and superuser can drop a table. so if you're not on that list, sorry bestie, it's not happening ๐Ÿ™ˆ

also important: if you just wanna empty a table of rows without destroying the table, do NOT drop it. use DELETE or TRUNCATE instead. different vibes entirely, iykyk.

now for the tea ๐Ÿ“: DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table. she does not leave loose ends. she cleans up. main character energy fr fr.

BUT. and this is the big but. if you wanna drop a table that's referenced by a view or a foreign-key constraint of another table, you gotta say CASCADE. no CASCADE, no drop.

and lowkey the details matter here: CASCADE will remove a dependent view entirely, but in the foreign-key case it will only remove the foreign-key constraint, not the other table entirely. so she's dramatic but she's precise. obsessed actually.


โœจ PARAMETERS โœจ

  • IF EXISTS โ€” don't throw an error if the table doesn't exist. she's not gonna yell at you for dropping something that's already gone. a notice is issued in this case, so you'll still know what's up. ๐Ÿซถ
  • name โ€” the name of the table to drop. optionally schema-qualified, so like myschema.mytable if you're feeling specific.
  • 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.15). yes, that's a chain reaction. yes, it can get big. she said "and i took that personally". ๐Ÿ”ฅ
  • RESTRICT โ€” refuse to drop the table if any objects depend on it. this is the default. she's cautious. she's responsible. she's the friend who says "bestie are you SURE" ๐Ÿ’–

โœจ EXAMPLES โœจ

wanna destroy two tables, films and distributors? okay. say less:

DROP TABLE films, distributors;

and that's it. no takebacks. no undo button. just vibes and consequences ๐Ÿ’€โœจ


โœจ COMPATIBILITY โœจ

ok so this command conforms to the SQL standard, except for two lil things:

  1. the standard only allows one table to be dropped per command (we allow a whole list, we're generous like that ๐ŸŽ€)
  2. the IF EXISTS option, which is a PostgreSQL extension โ€” standard doesn't have it, we do ๐Ÿฆ‹

โœจ SEE ALSO โœจ

go read those if you wanna create instead of destroy. balance, bestie ๐ŸŒธ


โš ๏ธ real talk: dropping a table is permanent. there is no "oops undo". CASCADE especially can take down a whole chain of dependent stuff. read twice, drop once. ๐Ÿ’€

and that's the whole page!! ๐Ÿ’– this one's from PostgreSQL 18.6, dated 2026 โ€” so if you're reading this in some other year, hi from the past, hope your tables are safe ๐Ÿซถโœจ bye bestie!! ๐ŸŽ€๐Ÿฆ‹๐Ÿ’…

๐Ÿ“ฆ where this page comes from