You are viewing the documentation for a prerelease version.

View Latest

DROP PRIMARY INDEX

The DROP PRIMARY INDEX statement allows you to drop an unnamed primary indexes.

Named primary indexes that are created using CREATE PRIMARY INDEX, can only be dropped using the DROP INDEX command.

drop-primary-index:

DROP PRIMARY INDEX ON named_keyspace_ref [USING GSI];

named-keyspace-ref(expression[,expression]*)

[ namespace-name :] keyspace-name

keyspace-name:

identifier that refers to the bucket name. Specifies the bucket as source for which the index needs to be created. You can add an optional namespace name to the keyspace name in this way:

namespace-name : keyspace-name

Currently, only the default namespace is available. For example, default:`travel-sample` indicates the travel-sample keyspace in the default namespace. If the namespace name is omitted, the default namespace in the current session is used.

USING GSI

In Couchbase Server 6.5 and later, the index type for a primary index must be Global Secondary Index (GSI). The USING GSI keywords are optional and may be omitted.

RBAC Privileges

User executing the DROP PRIMARY INDEX statement must have the Query Manage Index privilege granted on the keyspace/bucket. For more details about user roles, see Roles.

Example

The following example creates a primary index on the beer-sample bucket. Once the index creation statement comes back, system:indexes is queried for status of the index.

CREATE PRIMARY INDEX ON `beer-sample` USING GSI;
SELECT * FROM system:indexes;

Subsequently, the unnamed primary index is dropped with the following statement and it no longer is reported in the system:indexes output.

DROP PRIMARY INDEX ON `beer-sample` USING GSI;
SELECT * FROM system:indexes;