Skip to main content
The DROP SCHEMA removes a user-defined .
The “ statement performs a schema change. For more information about how online schema changes work in CockroachDB, see .

Required privileges

The user must have the DROP on the schema and on all tables in the schema. If the user is the owner of the schema, DROP privileges are not necessary.

Syntax

drop_schema syntax diagram

Parameters

ParameterDescription
IF EXISTSDrop the schema if it exists. If it does not exist, do not return an error.
schema_name_listThe schema, or a list of schemas, that you want to drop.
To drop a schema in a database other than the current database, specify the name of the database and the name of the schema, separated by a “.” (e.g., DROP SCHEMA IF EXISTS database.schema;).
CASCADEDrop all tables and views in the schema as well as all objects (such as and ) that depend on those tables.

CASCADE does not list objects it drops, so should be used cautiously.
RESTRICT(Default) Do not drop the schema if it contains any or .

Examples

Setup

To follow along, run to start a temporary, in-memory cluster with the sample dataset preloaded:

Drop a schema

Drop a schema with tables

To drop a schema that contains tables, you need to use the CASCADE keyword.

See also