DROP_TABLE(7pg13)
π NAME π
Hiii bestie π welcome to DROP TABLE(7) from the PostgreSQL 13.23 docs β this is literally the page about yeeting a table out of your database, and we're gonna read it together, no cap. β¨
πΈ SYNOPSIS πΈ
DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
π¦ DESCRIPTION π¦
Okay so DROP TABLE removes tables from the database. Only the table owner, the schema owner, and superuser can drop a table β that's the whole guest list, bestie. π
If you just wanna empty a table of rows without destroying the table itself, use DELETE(7) or TRUNCATE(7). Different vibe entirely. π«Ά
DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table. Iconic cleanup behavior, honestly. But listen: to drop a table that is referenced by a view or a foreign-key constraint of another table, CASCADE must be specified. And the parenthetical tea is important: 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. π
π PARAMETERS π
IF EXISTSβ Do not throw an error if the table does not exist. A notice is issued in this case. Chill little safety net. β¨nameβ The name (optionally schema-qualified) of the table to drop.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). Big main-character energy, but it will take dependents down with it. π₯RESTRICTβ Refuse to drop the table if any objects depend on it. This is the default. The cautious queen behavior. π
π EXAMPLES π
To destroy two tables, films and distributors:
DROP TABLE films, distributors;
β COMPATIBILITY β
This command conforms to the SQL standard, except that the standard only allows one table to be dropped per command, and apart from the IF EXISTS option, which is a PostgreSQL extension. Periodt. π«
π§ SEE ALSO π§
ALTER TABLE(ALTER_TABLE(7))CREATE TABLE(CREATE_TABLE(7))
bestie reminder: CASCADE is giving βIβm helpingβ but it can absolutely remove dependent objects. Read the dependency situation before you commit. ππ
okie dokie, that's the whole page β from PostgreSQL 13.23, dated 2025, DROP TABLE(7). mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-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