The DROP DATABASE statement removes a database and all its objects from a CockroachDB cluster.

Synopsis

DROP DATABASE IF EXISTS name

Required Privileges

The user must have the DROP privilege on the database and on all tables in the database.

Usage

To remove a database from a CockroachDB cluster, use the DROP DATABASE statement followed by a database name:

> DROP DATABASE db1;

To avoid an error in case the database does not exist, you can include IF EXISTS:

> DROP DATABASE IF EXISTS db1;

Example

> SHOW DATABASES;
+----------+
| Database |
+----------+
| db1      |
| system   |
+----------+
> DROP DATABASE db1;

> DROP DATABASE db2;
pq: database "db2" does not exist
> DROP DATABASE IF EXISTS db2;

> SHOW DATABASES;
+----------+
| Database |
+----------+
| system   |
+----------+

See Also



Yes No