DROP SCHEMA
DROP SCHEMA removes one or more schemas from the current database, along with their objects if CASCADE is specified.
Limits
You cannot drop the default public schema.
Syntax
DROP SCHEMA [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]| Parameter | Description |
|---|---|
IF EXISTS | Suppresses an error if the schema does not exist. Use this clause in scripts so the statement does not fail when run against a nonexistent schema. |
CASCADE | Drops the schema and all objects it contains, such as tables and functions. |
RESTRICT | Refuses to drop the schema if it contains any objects. This is the default. |
Examples
Drop a schema only if it is empty. If the schema contains any objects, the statement returns an error:
DROP SCHEMA mystuff RESTRICT;Drop a schema and all its objects. Use this with caution in production environments:
DROP SCHEMA mystuff CASCADE; -- Replace mystuff with the name of your schema.Drop a schema if it exists, or do nothing if it does not. This is safe to use in automation scripts:
DROP SCHEMA IF EXISTS mystuff;