DROP_TABLE(7pg17)
π DROP TABLE (7pg17) β the PostgreSQL 17.11 glow-up edition β¨
okay bestie, listen up, because this one's about the single most final thing you can do to a table. we're talking DROP TABLE from the PostgreSQL 17.11 docs β yes, that PostgreSQL, the iconic one. π
β¨ NAME β¨
DROP_TABLE β remove a table π«Ά (yes, remove. like, gone gone. π)
β¨ SYNOPSIS β¨
DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
look at her. three little pieces and she can end a whole table's career. π
πΈ DESCRIPTION πΈ
so DROP TABLE removes tables from the database. periodt. π
ngl there's a whole guest list for who's allowed to do this: only the table owner, the schema owner, and a superuser can drop a table. that's it. that's the list. π
quick vibe check though β if you just wanna empty a table of rows without destroying the table itself, that is not this command. use DELETE or TRUNCATE instead. like, keep the container, toss the contents. π
here's the part where she's actually kind of ruthless: DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table. no asking, no warning, she just does it. π§
but β and this is the important bit β to drop a table that's referenced by a view or a foreign-key constraint of another table, you must specify CASCADE. and the tea on CASCADE is wild: it 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. yes, that distinction matters. no cap. π₯
π PARAMETERS π
IF EXISTSβ Do not throw an error if the table does not exist. A notice is issued in this case. (basically: "no table? no problem, bestie, here's a lil notice instead of a whole tantrum." β¨)nameβ The name (optionally schema-qualified) of the table to drop. (say her full name, schema and all, if you wanna be fancy π )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). (the "and everything that depends on that" part is giving chain reaction π)RESTRICTβ Refuse to drop the table if any objects depend on it. This is the default. (the safe, responsible, main-character-with-a-5-year-plan option π«Ά)
β EXAMPLES β
To destroy two tables, films and distributors:
DROP TABLE films, distributors;
two at once. efficient. iconic. slightly menacing. π¬π’π
β οΈ careful bestie, there is literally no undo button on this one. CASCADE especially is not a drill.
π COMPATIBILITY π
This command conforms to the SQL standard β with two lil asterisks:
- the standard only allows one table to be dropped per command (PostgreSQL lets you do a whole list, we're just built different π )
- and apart from the
IF EXISTSoption, which is a PostgreSQL extension π
π¦ SEE ALSO π¦
ALTER TABLE(ALTER_TABLE(7))CREATE TABLE(CREATE_TABLE(7))
(like, if you're not ready to commit to destruction, those two are right there. π§β¨)
and that's the whole page, bestie!! π this lil slice of documentation is PostgreSQL 17.11, dated 2026, and it's DROP TABLE(7) β go forth responsibly, don't CASCADE on a Friday, ily π«Άππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms