Skip to main content
The DROP TABLE statement removes a table and all its indexes from a database.
The DROP TABLE statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.

Required privileges

The user must have the DROP privilege on the specified table(s). If CASCADE is used, the user must have the privileges required to drop each dependent object as well.

Synopsis

drop_table syntax diagram

Parameters

Viewing schema changes

This schema change statement is registered as a job. You can view long-running jobs with SHOW JOBS.

Examples

Setup

The following examples use MovR, a fictional vehicle-sharing application, to demonstrate CockroachDB SQL statements. For more information about the MovR example application and dataset, see MovR: A Global Vehicle-sharing App. To follow along, run cockroach demo to start a temporary, in-memory cluster with the movr dataset preloaded:

Remove a table (no dependencies)

In this example, other objects do not depend on the table being dropped.

Remove a table and dependent objects with CASCADE

In this example, a foreign key from a different table references the table being dropped. Therefore, it’s only possible to drop the table while simultaneously dropping the dependent foreign key constraint using CASCADE.
To see how users is referenced from vehicles, you can use the SHOW CREATE statement. SHOW CREATE shows how the columns in a table are created, including data types, default values, indexes, and constraints.
Use a SHOW CREATE TABLE statement to verify that the foreign key constraint has been removed from vehicles.

See also