DROP TABLE

A DDL command to remove a table

DROP TABLE is a DDL command to remove a table.

DROP TABLE has always been present in PostgreSQL.

Change history

Examples

Basic DROP TABLE execution:

postgres=# DROP TABLE foo;
DROP TABLE

postgres=# DROP TABLE foo, bar;
DROP TABLE

Safely attempting to drop a table which might not exist:

postgres=# DROP TABLE if exists foo;
NOTICE:  table "foo" does not exist, skipping
DROP TABLE

Dropping a table with dependencies:

postgres=# DROP TABLE bar;
ERROR:  cannot drop table bar because other objects depend on it
DETAIL:  constraint baz_id_fkey on table baz depends on table bar
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

postgres=# DROP TABLE bar CASCADE;
NOTICE:  drop cascades to constraint baz_id_fkey on table baz
DROP TABLE

Categories

DDL

See also

ALTER TABLE, CREATE TABLE