January 26, 2025
+ 12
How to drop primary and secondary indexes.

Introduction

You can drop primary and secondary indexes when you do not need them any more. Dropping an index that has replicas will also drop all of the replica indexes too.

If you want to try out the examples in this section, follow the instructions given in Do a Quick Install to install Couchbase Server, configure a cluster, and load a sample dataset. Read the following for further information about the tools available for editing and executing queries:

Dropping a Primary Index

You can drop a primary index using a SQL++ statement or an SDK call.

The SDK calls only enable you to drop indexes in the default collection and default scope within a bucket. A SQL++ statement enables you to drop indexes in any collection and scope within a bucket.

To drop an unnamed primary index, use the DROP PRIMARY INDEX statement.

To drop a named primary index, use the DROP INDEX statement. There are two possible syntaxes:

  • Specify the index name, then use the ON keyword to specify the keyspace which contains the index.

  • Specify the keyspace and index name using dotted notation.


Context

For this example, set the query context to the inventory scope in the travel sample dataset. For more information, see Setting the Query Context.

Queries

The following query drops an unnamed primary index from the airline keyspace.

DROP PRIMARY INDEX ON airline;

The following query drops a named primary index from the airline keyspace.

DROP INDEX travel_primary ON airline;

The following query drops the index in exactly the same way, but uses alternative syntax.

DROP INDEX airline.travel_primary;

For further details and examples, refer to DROP PRIMARY INDEX and DROP INDEX.

Dropping a Secondary Index

You can drop a secondary index using a SQL++ statement or an SDK call.

The SDK calls only enable you to drop indexes in the default collection and default scope within a bucket. A SQL++ statement enables you to drop indexes in any collection and scope within a bucket.

To drop a a secondary index, use the DROP INDEX statement. There are two possible syntaxes:

  • Specify the index name, then use the ON keyword to specify the keyspace which contains the index.

  • Specify the keyspace and index name using dotted notation.


Context

For this example, set the query context to the inventory scope in the travel sample dataset. For more information, see Setting the Query Context.

Queries

The following query drops a named index from the airline keyspace.

DROP INDEX `idx-name` ON airline;

The following query drops the index in exactly the same way, but uses alternative syntax.

DROP INDEX airline.`idx-name`;

For further details and examples, refer to DROP INDEX.

Reference and explanation:

Administrator guides:

Indexes with SDKs: