DROP SCHEMA

Syntax

DROP SCHEMA schema_name;

Description

Drops a Schema from the current Database. It can only be executed by the Schema owner. A Schema cannot be dropped if it contains any relations.

DROP SCHEMA cannot be undone. Use it with care!

Arguments

schema_name

The name of the Schema to drop. Optionally, a fully qualified Schema name can be provided to drop a Schema from a Database other than the current Database. For case-sensitive names, the name must be wrapped in double quotes, otherwise, the lowercased name will be used.

Examples

Drop a Schema in the current Database

The following drops the Schema in the current Database demodb:

demodb.public/<no-store># LIST SCHEMAS;
    Name    | Default |  Owner   |      Created at      |      Updated at
------------+---------+----------+----------------------+-----------------------
  public    |        | sysadmin | 2024-06-06T21:35:58Z | 2024-06-06T21:35:58Z
  other     |         | sysadmin | 2024-06-06T21:35:58Z | 2024-06-06T21:35:58Z
  newschema |         | sysadmin | 2024-06-06T21:35:58Z | 2024-06-06T21:35:58Z
demodb.public/<no-store># DROP SCHEMA other;
demodb.public/<no-store># LIST SCHEMAS;
    Name    | Default |  Owner   |      Created at      |      Updated at
------------+---------+----------+----------------------+-----------------------
  public    |        | sysadmin | 2024-06-06T21:35:58Z | 2024-06-06T21:35:58Z
  newschema |         | sysadmin | 2024-06-06T21:35:58Z | 2024-06-06T21:35:58Z

Drop a Schema in a specific Database

The following drops the Schema NewSchema in the specified Database otherdb:

demodb.public/<no-store># LIST SCHEMAS IN DATABASE otherdb;
    Name    | Default |  Owner   |      Created at      |      Updated at
------------+---------+----------+----------------------+-----------------------
  public    |        | sysadmin | 2024-06-06T21:36:18Z | 2024-06-06T21:36:18Z
  NewSchema |         | sysadmin | 2024-06-06T21:36:18Z | 2024-06-06T21:36:18Z
demodb.public/<no-store># DROP SCHEMA otherdb."NewSchema";
demodb.public/<no-store># LIST SCHEMAS IN DATABASE otherdb;
   Name  | Default |  Owner   |      Created at      |      Updated at
---------+---------+----------+----------------------+-----------------------
  public |        | sysadmin | 2024-06-06T21:36:18Z | 2024-06-06T21:36:18Z

Last updated