Updated on 2025-03-13 GMT+08:00

DROP SCHEMA

Description

Deletes a schema from the current database.

Precautions

  • Only the schema owner or a user granted with the DROP permission can run the DROP SCHEMA command. System administrators have this permission by default.
  • Only the initial user and O&M administrators can run the DROP SCHEMA command for O&M administrators. Other users cannot run DROP SCHEMA for O&M administrators.
  • You are not allowed to drop DBE_PLDEVELOPER when allow_system_table_mods is disabled.

Syntax

DROP SCHEMA [ IF EXISTS ] schema_name [, ...] [ CASCADE | RESTRICT ];

Parameters

  • IF EXISTS

    Reports a notice instead of an error if the specified schema does not exist.

  • schema_name

    Specifies the name of the schema to be deleted.

    Value range: an existing schema name

  • CASCADE | RESTRICT
    • CASCADE: automatically deletes all the objects contained in the schema.
    • RESTRICT: refuses to delete the schema if the schema contains objects. This is the default action.

Schemas beginning with pg_temp or pg_toast_temp are for internal use. Do not delete them. Otherwise, unexpected consequences may be incurred.

The schema currently being used cannot be deleted. To delete it, switch to another schema first.

Examples

See Examples in section "CREATE SCHEMA."

Helpful Links

ALTER SCHEMA and CREATE SCHEMA.