Skip to main content
The DROP INDEX removes indexes from tables. The DROP INDEX statement performs a schema change. For more information about how online schema changes work in CockroachDB, see .

Synopsis

drop_index syntax diagram

Required privileges

The user must have the CREATE on each specified table.

Parameters

ParameterDescription
IF EXISTSDrop the named indexes if they exist; if they do not exist, do not return an error.
table\_nameThe name of the table with the index you want to drop. Find table names with .
index\_nameThe name of the index you want to drop. Find index names with . You cannot drop a table’s primary index.
CASCADEDrop all objects (such as ) that depend on the indexes. CASCADE does not list objects it drops, so should be used cautiously. To drop an index created with , you do not need to use CASCADE.
RESTRICT(Default) Do not drop the indexes if any objects (such as ) depend on them.
CONCURRENTLYOptional, no-op syntax for PostgreSQL compatibility. All indexes are dropped concurrently in CockroachDB.

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 an index with no dependencies

created as part of a statement cannot be removed without using CASCADE. Unique indexes created with do not have this limitation. Suppose you create an index on the name and city columns of the users table:
You can drop this index with the DROP INDEX statement:

Remove an index and dependent objects with 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. Suppose you create a constraint on the id and name columns of the users table:
If no index exists on id and name, CockroachDB automatically creates an index:
The UNIQUE constraint is dependent on the id_name_unique index, so you cannot drop the index with a simple DROP INDEX statement:
To drop an index and its dependent objects, you can use CASCADE:

See also