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 theDROP on the specified table(s). If CASCADE is used, the user must have the privileges required to drop each dependent object as well.
Synopsis
Parameters
| Parameter | Description |
|---|---|
IF EXISTS | Drop the table if it exists; if it does not exist, do not return an error. |
table\_name\_list | A comma-separated list of table names. To find table names, use . |
CASCADE | Drop all objects (such as and ) that depend on the table. CASCADE does not list objects it drops, so should be used cautiously. |
RESTRICT | (Default) Do not drop the table if any objects (such as and ) depend on it. |
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.
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.
SHOW CREATE TABLE statement to verify that the foreign key constraint has been removed from vehicles.

