On this page
Warning:CockroachDB v1.0 is no longer supported. For more details, see the Release Support Policy.
DROP DATABASE statement removes a database and all its objects from a CockroachDB cluster.
The user must have the
DROP privilege on the database and on all tables in the database.
||Drop the database if it exists; if it does not exist, do not return an error.|
||The name of the database you want to drop.|
> 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
> DROP DATABASE IF EXISTS db2; > SHOW DATABASES;
+----------+ | Database | +----------+ | system | +----------+
DROP DATABASEdrops 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.