DROP_TABLE(7pg13)

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

πŸ’– 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 🧚


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