DROP SCHEMA

A DDL command to remove a schema.

DROP SCHEMA is a DDL command to remove a schema.

DROP SCHEMA was added in PostgreSQL 7.3.

Change history

Examples

Dropping an empty schema:

postgres=# CREATE SCHEMA foo;
CREATE SCHEMA

postgres=# DROP SCHEMA foo;
DROP SCHEMA

Dropping a non-empty schema:

postgres=# CREATE SCHEMA foo;
CREATE SCHEMA

postgres=# CREATE TABLE foo.bar (id INT, val TEXT);
CREATE TABLE

postgres=# DROP SCHEMA foo;
ERROR:  cannot drop schema foo because other objects depend on it
DETAIL:  table foo.bar depends on schema foo
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

postgres=# DROP SCHEMA foo CASCADE;
NOTICE:  drop cascades to table foo.bar
DROP SCHEMA

Categories

DDL, Schema (namespace)

See also

CREATE SCHEMA, ALTER SCHEMA, pg_namespace