Skip to content

Files

Latest commit

02fcb5f · Aug 30, 2016

History

History
73 lines (56 loc) · 1.33 KB

drop-database.md

File metadata and controls

73 lines (56 loc) · 1.33 KB
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.

Synopsis

{% include sql/diagrams/drop_database.html %}

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