title | summary | toc |
---|---|---|
DROP DATABASE |
The DROP DATABASE statement removes a database and all its objects from a CockroachDB cluster. |
false |
The DROP DATABASE
statement removes a database and all its objects from a CockroachDB cluster.
{% include sql/diagrams/drop_database.html %}
The user must have the DROP
privilege on the database and on all tables in the database.
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;
> 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 |
+----------+