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/demostore# LIST DATABASES;
   Name  | Default |  Owner   |      Created at      |      Updated at
---------+---------+----------+----------------------+-----------------------
  db     |        | sysadmin | 2023-02-23T02:04:40Z | 2023-02-23T02:04:40Z
  DemoDB |         | sysadmin | 2023-02-23T02:04:44Z | 2023-02-23T02:04:44Z

<strong>db.public/demostore# DROP DATABASE "DemoDB";
</strong>db.public/demostore# LIST DATABASES;
  Name | Default |  Owner   |      Created at      |      Updated at
-------+---------+----------+----------------------+-----------------------
  db   |        | sysadmin | 2023-02-23T02:04:40Z | 2023-02-23T02:04:40Z

Drop user's current Database

The following shows when dropping a user's current Database, the session's current Database is also wiped, but one can be set with USE from LIST DATABASES:

otherdb.public/demostore# DROP DATABASE otherdb;
<no-db>/demostore# LIST DATABASES;
   Name  | Default |  Owner   |      Created at      |      Updated at       
---------+---------+----------+----------------------+-----------------------
  testdb |        | sysadmin | 2023-01-11T19:59:26Z | 2023-01-11T19:59:26Z  
<no-db>/demostore# USE DATABASE testdb;
testdb.public/demostore# 

Last updated