> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# DROP INDEX

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `DROP INDEX` <InternalLink path="sql-statements">statement</InternalLink> removes indexes from tables.

<Note>
  The \`\` statement performs a schema change. For more information about how online schema changes work in CockroachDB, see <InternalLink path="online-schema-changes">Online Schema Changes</InternalLink>.
</Note>

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/s4duaCBAbwxHbmt7/images/sql-diagrams/v26.3/drop_index.svg?fit=max&auto=format&n=s4duaCBAbwxHbmt7&q=85&s=44bcb95faa336708c5838a0aadedc696" alt="drop_index syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="569" height="211" data-path="images/sql-diagrams/v26.3/drop_index.svg" />

## Required privileges

The user must have the `CREATE` <InternalLink path="security-reference/authorization#managing-privileges">privilege</InternalLink> on each specified table.

## Parameters

| Parameter      | Description                                                                                                                                                                                                                                                                                                                                                   |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `IF EXISTS`    | Drop the named indexes if they exist; if they do not exist, do not return an error.                                                                                                                                                                                                                                                                           |
| `table_name`   | The name of the table with the index you want to drop. Find table names with <InternalLink path="show-tables">`SHOW TABLES`</InternalLink>.                                                                                                                                                                                                                   |
| `index_name`   | The name of the index you want to drop. Find index names with <InternalLink path="show-index">`SHOW INDEX`</InternalLink>.<br /><br />You cannot drop a table's primary index.                                                                                                                                                                                |
| `CASCADE`      | Drop all objects (such as <InternalLink path="constraints">constraints</InternalLink>) that depend on the indexes. `CASCADE` does not list objects it drops, so should be used cautiously.<br /><br /> To drop an index created with <InternalLink path="create-index#unique-indexes">`CREATE UNIQUE INDEX`</InternalLink>, you do not need to use `CASCADE`. |
| `RESTRICT`     | *(Default)* Do not drop the indexes if any objects (such as <InternalLink path="constraints">constraints</InternalLink>) depend on them.                                                                                                                                                                                                                      |
| `CONCURRENTLY` | Optional, 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 <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>.

## Examples

#### Setup

To follow along, run <InternalLink path="cockroach-demo">`cockroach demo`</InternalLink> to start a temporary, in-memory cluster with the <InternalLink path="movr">`movr`</InternalLink> sample dataset preloaded:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach demo
```

### Remove an index with no dependencies

<InternalLink path="create-index">`UNIQUE` indexes</InternalLink> created as part of a <InternalLink path="create-table">`CREATE TABLE`</InternalLink> statement cannot be removed without using [`CASCADE`](drop-index.html#remove-an-index-and-dependent-objects-with-cascade). Unique indexes created with <InternalLink path="create-index">`CREATE INDEX`</InternalLink> do not have this limitation.

Suppose you create an index on the `name` and `city` columns of the `users` table:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> CREATE INDEX ON users (name, city);
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW INDEXES FROM users;
```

```
  table_name |     index_name      | non_unique | seq_in_index | column_name | direction | storing | implicit | visible
-------------+---------------------+------------+--------------+-------------+-----------+---------+----------+----------
  users      | users_name_city_idx |     t      |            1 | name        | ASC       |    f    |    f     |    t
  users      | users_name_city_idx |     t      |            2 | city        | ASC       |    f    |    f     |    t
  users      | users_name_city_idx |     t      |            3 | id          | ASC       |    f    |    t     |    t
  users      | users_pkey          |     f      |            1 | city        | ASC       |    f    |    f     |    t
  users      | users_pkey          |     f      |            2 | id          | ASC       |    f    |    f     |    t
  users      | users_pkey          |     f      |            3 | name        | N/A       |    t    |    f     |    t
  users      | users_pkey          |     f      |            4 | address     | N/A       |    t    |    f     |    t
  users      | users_pkey          |     f      |            5 | credit_card | N/A       |    t    |    f     |    t
(8 rows)
```

You can drop this index with the `DROP INDEX` statement:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP INDEX users@users_name_city_idx;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW INDEXES FROM users;
```

```
  table_name | index_name | non_unique | seq_in_index | column_name | direction | storing | implicit | visible
-------------+------------+------------+--------------+-------------+-----------+---------+----------+----------
  users      | users_pkey |     f      |            1 | city        | ASC       |    f    |    f     |    t
  users      | users_pkey |     f      |            2 | id          | ASC       |    f    |    f     |    t
  users      | users_pkey |     f      |            3 | name        | N/A       |    t    |    f     |    t
  users      | users_pkey |     f      |            4 | address     | N/A       |    t    |    f     |    t
  users      | users_pkey |     f      |            5 | credit_card | N/A       |    t    |    f     |    t
(5 rows)
```

### Remove an index and dependent objects with `CASCADE`

`CASCADE` drops <em>all</em> 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 <InternalLink path="unique">`UNIQUE`</InternalLink> constraint on the `id` and `name` columns of the `users` table:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> ALTER TABLE users ADD CONSTRAINT id_name_unique UNIQUE (id, name);
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW CONSTRAINTS from users;
```

```
  table_name | constraint_name | constraint_type |            details             | validated
-------------+-----------------+-----------------+--------------------------------+------------
  users      | id_name_unique  | UNIQUE          | UNIQUE (id ASC, name ASC)      |     t
  users      | users_pkey      | PRIMARY KEY     | PRIMARY KEY (city ASC, id ASC) |     t
(2 rows)
```

If no index exists on `id` and `name`, CockroachDB automatically creates an index:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW INDEXES from users;
```

```
  table_name |   index_name   | non_unique | seq_in_index | column_name | direction | storing | implicit | visible
-------------+----------------+------------+--------------+-------------+-----------+---------+----------+----------
  users      | id_name_unique |     f      |            1 | id          | ASC       |    f    |    f     |    t
  users      | id_name_unique |     f      |            2 | name        | ASC       |    f    |    f     |    t
  users      | id_name_unique |     f      |            3 | city        | ASC       |    t    |    t     |    t
  users      | users_pkey     |     f      |            1 | city        | ASC       |    f    |    f     |    t
  users      | users_pkey     |     f      |            2 | id          | ASC       |    f    |    f     |    t
  users      | users_pkey     |     f      |            3 | name        | N/A       |    t    |    f     |    t
  users      | users_pkey     |     f      |            4 | address     | N/A       |    t    |    f     |    t
  users      | users_pkey     |     f      |            5 | credit_card | N/A       |    t    |    f     |    t
(8 rows)
```

The `UNIQUE` constraint is dependent on the `id_name_unique` index, so you cannot drop the index with a simple `DROP INDEX` statement:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP INDEX id_name_unique;
```

```
ERROR: index "id_name_unique" is in use as unique constraint
SQLSTATE: 2BP01
HINT: use CASCADE if you really want to drop it.
```

To drop an index and its dependent objects, you can use `CASCADE`:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP INDEX id_name_unique CASCADE;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW INDEXES from users;
```

```
  table_name | index_name | non_unique | seq_in_index | column_name | direction | storing | implicit | visible
-------------+------------+------------+--------------+-------------+-----------+---------+----------+----------
  users      | users_pkey |     f      |            1 | city        | ASC       |    f    |    f     |    t
  users      | users_pkey |     f      |            2 | id          | ASC       |    f    |    f     |    t
  users      | users_pkey |     f      |            3 | name        | N/A       |    t    |    f     |    t
  users      | users_pkey |     f      |            4 | address     | N/A       |    t    |    f     |    t
  users      | users_pkey |     f      |            5 | credit_card | N/A       |    t    |    f     |    t
(5 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW CONSTRAINTS from users;
```

```
  table_name | constraint_name | constraint_type |            details             | validated
-------------+-----------------+-----------------+--------------------------------+------------
  users      | users_pkey      | PRIMARY KEY     | PRIMARY KEY (city ASC, id ASC) |   true
(1 row)
```

## See also

* <InternalLink path="indexes">Indexes</InternalLink>
* <InternalLink path="online-schema-changes">Online Schema Changes</InternalLink>
* <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>
