DROP_TABLE(7pg18)
๐ 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 likemyschema.mytableif 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:
- the standard only allows one table to be dropped per command (we allow a whole list, we're generous like that ๐)
- the
IF EXISTSoption, which is a PostgreSQL extension โ standard doesn't have it, we do ๐ฆ
โจ SEE ALSO โจ
ALTER TABLE(ALTER_TABLE(7))CREATE TABLE(CREATE_TABLE(7))
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
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms