> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# DROP DATABASE

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `DROP DATABASE` <InternalLink path="sql-statements">statement</InternalLink> removes a database and all its objects from a CockroachDB cluster.

The `DROP DATABASE` statement performs a schema change. For more information about how online schema changes work in CockroachDB, see <InternalLink path="online-schema-changes">Online Schema Changes</InternalLink>.

## Required privileges

The user must have the `DROP` <InternalLink path="security-reference/authorization#managing-privileges">privilege</InternalLink> on the database and on all tables in the database.

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/N8jqu5GnKPMC09TX/images/sql-diagrams/v25.4/drop_database.svg?fit=max&auto=format&n=N8jqu5GnKPMC09TX&q=85&s=0f64a7a9b5a4bfc200d691aff598c96f" alt="drop_database syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="705" height="113" data-path="images/sql-diagrams/v25.4/drop_database.svg" />

## 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. You cannot drop a database if it is set as the <InternalLink path="sql-name-resolution#current-database">current database</InternalLink> or if <InternalLink path="set-vars">`sql\_safe\_updates = true`</InternalLink>.                                          |
| `CASCADE`   | *(Default)* Drop all tables and views in the database as well as all objects (such as <InternalLink path="constraints">constraints</InternalLink> and <InternalLink path="views">views</InternalLink>) that depend on those tables.  `CASCADE` does not list objects it drops, so should be used cautiously. |
| `RESTRICT`  | Do not drop the database if it contains any <InternalLink path="create-table">tables</InternalLink> or <InternalLink path="create-view">views</InternalLink>.                                                                                                                                                |

## Viewing schema changes

This schema change statement is registered as a job. You can view long-running jobs with <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>.

## Examples

#### Setup

To follow along, run <InternalLink path="cockroach-demo">`cockroach demo`</InternalLink> to start a temporary, in-memory cluster with the <InternalLink path="movr">`movr`</InternalLink> sample dataset preloaded:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach demo
```

### Drop a database and its objects (`CASCADE`)

For non-interactive sessions (e.g., client applications), `DROP DATABASE` applies the `CASCADE` option by default, which drops all tables and views in the database as well as all objects (such as <InternalLink path="constraints">constraints</InternalLink> and <InternalLink path="views">views</InternalLink>) that depend on those tables.

For interactive sessions from the <InternalLink path="cockroach-sql">built-in SQL client</InternalLink>, either the `CASCADE` option must be set explicitly or the `--unsafe-updates` flag must be set when starting the shell.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW TABLES FROM movr;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  schema_name |         table_name         | type  | estimated_row_count
--------------+----------------------------+-------+----------------------
  public      | promo_codes                | table |                1000
  public      | rides                      | table |                 500
  public      | user_promo_codes           | table |                   0
  public      | users                      | table |                  50
  public      | vehicle_location_histories | table |                1000
  public      | vehicles                   | table |                  15
(6 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP DATABASE movr;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ERROR: rejected (sql_safe_updates = true): DROP DATABASE on current database
SQLSTATE: 01000
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> USE defaultdb;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP DATABASE movr;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ERROR: rejected (sql_safe_updates = true): DROP DATABASE on non-empty database without explicit CASCADE
SQLSTATE: 01000
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP DATABASE movr CASCADE;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW TABLES FROM movr;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ERROR: target database or schema does not exist
SQLSTATE: 3F000
```

### Prevent dropping a non-empty database (`RESTRICT`)

When a database is not empty, the `RESTRICT` option prevents the database from being dropped:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW TABLES FROM movr;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  schema_name |         table_name         | type  | estimated_row_count
--------------+----------------------------+-------+----------------------
  public      | promo_codes                | table |                1000
  public      | rides                      | table |                 500
  public      | user_promo_codes           | table |                   0
  public      | users                      | table |                  50
  public      | vehicle_location_histories | table |                1000
  public      | vehicles                   | table |                  15
(6 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> USE defaultdb;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP DATABASE movr RESTRICT;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ERROR: database "movr" is not empty and RESTRICT was specified
SQLSTATE: 2BP01
```

## See also

* <InternalLink path="create-database">`CREATE DATABASE`</InternalLink>
* <InternalLink path="show-databases">`SHOW DATABASES`</InternalLink>
* <InternalLink path="alter-database#rename-to">`ALTER DATABASE... RENAME TO`</InternalLink>
* <InternalLink path="set-vars">`SET DATABASE`</InternalLink>
* <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>
* <InternalLink path="sql-statements">SQL Statements</InternalLink>
* <InternalLink path="online-schema-changes">Online Schema Changes</InternalLink>
