DROP DATABASE

On this page Carat arrow pointing down

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.

Parameters

Parameter Description
IF EXISTS Drop the database if it exists; if it does not exist, do not return an error.
name The name of the database you want to drop.

Examples

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

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

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

> DROP DATABASE IF EXISTS db2;

> SHOW DATABASES;
+----------+
| Database |
+----------+
| system   |
+----------+
Warning:
DROP DATABASE drops all tables within the database as well as objects dependent on the tables without listing the tables or the dependent objects. This can lead to inadvertent and difficult-to-recover losses. To avoid potential harm, we recommend dropping objects individually in most cases.

See Also


Yes No
On this page

Yes No