DROP DATABASE

Syntax

DROP DATABASE database_name;

Description

Drops an existing Database. It can only be executed by the Database owner. A Database cannot be dropped if it contains any non-empty schemas.

DROP DATABASE cannot be undone. Use it with care!

If the user's current Database is dropped, a new Database will need to be set for the ongoing sessions. See USE.

Arguments

database_name

The name of the Database to drop. For case-sensitive names, the name must be wrapped in double quotes, otherwise, the lowercased name will be used.

Examples

Drop a Database

The following shows how to drop the Database named DemoDB:

db.public/<no-store># LIST DATABASES;
+------------+-------------+------------+-------------------------------+
|  Name      |  Is Default |  Owner     |  Created At                   |
+============+=============+============+===============================+
| DemoDB     | false       | sysadmin   | 2024-05-09 21:52:43 +0000 UTC |
+------------+-------------+------------+-------------------------------+
| db         | true        | sysadmin   | 2024-05-09 21:52:33 +0000 UTC |
+------------+-------------+------------+-------------------------------+
db.public/<no-store># DROP DATABASE "DemoDB";
+------------+------------+------------+------------------------------------------+
|  Type      |  Name      |  Command   |  Summary                                 |
+============+============+============+==========================================+
| database   | DemoDB     | DROP       | database "DemoDB" was successfully       |
|            |            |            | dropped                                  |
+------------+------------+------------+------------------------------------------+

Drop user's current Database

The following shows when dropping the current Database db, the session's current Database is also wiped. A new Database can be set with USE from LIST DATABASES for the current session, and with SET DEFAULT as a default for the current Organization:

db.public/<no-store># DROP DATABASE db;
+------------+------------+------------+----------------------------------------+
|  Type      |  Name      |  Command   |  Summary                               |
+============+============+============+========================================+
| database   | db         | DROP       | database "db" was successfully dropped |
+------------+------------+------------+----------------------------------------+
<no-db>/<no-store># LIST DATABASES;
+------------+-------------+------------+-------------------------------+
|  Name      |  Is Default |  Owner     |  Created At                   |
+============+=============+============+===============================+
| otherdb    | false       | sysadmin   | 2024-05-09 21:56:57 +0000 UTC |
+------------+-------------+------------+-------------------------------+
<no-db>/<no-store># USE DATABASE otherdb;
+------------+------------+------------+--------------------------+
|  Type      |  Name      |  Command   |  Summary                 |
+============+============+============+==========================+
| database   | otherdb    | USE        | using database "otherdb" |
+------------+------------+------------+--------------------------+
otherdb.public/<no-store>#

Last updated