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/demostore# show SCHEMAS;
+------------+-------------+------------+-------------------------------+
|  Name      |  Is Default |  Owner     |  Created At                   |
+============+=============+============+===============================+
| public     | true        | sysadmin   | 2024-07-02 16:23:26 +0000 UTC |
+------------+-------------+------------+-------------------------------+
| otherdb    | false       | sysadmin   | 2024-07-02 21:43:27 +0000 UTC |
+------------+-------------+------------+-------------------------------+
| newschema  | false       | sysadmin   | 2024-07-03 15:32:21 +0000 UTC |
+------------+-------------+------------+-------------------------------+
demodb.public/demostore# DROP SCHEMA newschema;
+------------+------------------+------------+------------------------------------------+
|  Type      |  Name            |  Command   |  Summary                                 |
+============+==================+============+==========================================+
| schema     | demodb.newschema | DROP       | schema "demodb.newschema" was            |
|            |                  |            | successfully dropped                     |
+------------+------------------+------------+------------------------------------------+
demodb.public/<no-store># LIST SCHEMAS;
+------------+-------------+------------+-------------------------------+
|  Name      |  Is Default |  Owner     |  Created At                   |
+============+=============+============+===============================+
| public     | true        | sysadmin   | 2024-07-02 16:23:26 +0000 UTC |
+------------+-------------+------------+-------------------------------+
| otherdb    | false       | sysadmin   | 2024-07-02 21:43:27 +0000 UTC |
+------------+-------------+------------+-------------------------------+

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      |  Is Default |  Owner     |  Created At                   |
+============+=============+============+===============================+
| S1         | false       | sysadmin   | 2024-07-02 21:44:59 +0000 UTC |
+------------+-------------+------------+-------------------------------+
| public     | true        | sysadmin   | 2024-07-02 21:21:18 +0000 UTC |
+------------+-------------+------------+-------------------------------+
| NewSchema  | false       | sysadmin   | 2024-07-02 21:21:25 +0000 UTC |
+------------+-------------+------------+-------------------------------+
demodb.public/<no-store># DROP SCHEMA otherdb."NewSchema";
+------------+-------------------+------------+------------------------------------------+
|  Type      |  Name             |  Command   |  Summary                                 |
+============+===================+============+==========================================+
| schema     | otherdb.NewSchema | DROP       | schema "otherdb.NewSchema" was           |
|            |                   |            | successfully dropped                     |
+------------+-------------------+------------+------------------------------------------+
demodb.public/<no-store># LIST SCHEMAS IN DATABASE otherdb;
+------------+-------------+------------+-------------------------------+
|  Name      |  Is Default |  Owner     |  Created At                   |
+============+=============+============+===============================+
| S1         | false       | sysadmin   | 2024-07-02 21:44:59 +0000 UTC |
+------------+-------------+------------+-------------------------------+
| public     | true        | sysadmin   | 2024-07-02 21:21:18 +0000 UTC |
+------------+-------------+------------+-------------------------------+

Last updated