Skip to main content
The DROP TABLE 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 .

Required privileges

The user must have the DROP 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 .

Examples

Setup

To follow along, run to start a temporary, in-memory cluster with the sample 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 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. CASCADE drops all dependent objects without listing them, which can lead to inadvertent and difficult-to-recover losses. To avoid potential harm, we recommend dropping objects individually in most cases.
To see how users is referenced from vehicles, you can use the 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