Edit

DROP INDEX (Transact-SQL)

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics SQL database in Microsoft Fabric

Removes one or more relational, spatial, filtered, or XML indexes from the current database. You can drop a clustered index and move the resulting table to another filegroup or partition scheme in a single transaction by specifying the MOVE TO option.

The DROP INDEX statement doesn't apply to indexes created by defining PRIMARY KEY or UNIQUE constraints. To remove the constraint and corresponding index, use ALTER TABLE with the DROP CONSTRAINT clause.

Important

The syntax defined in <drop_backward_compatible_index> will be removed in a future version of SQL Server. Avoid using this syntax in new development work, and plan to modify applications that currently use the feature. Use the syntax specified under <drop_relational_or_xml_or_spatial_index> instead. XML indexes can't be dropped using backward compatible syntax.

Transact-SQL syntax conventions

Syntax

Syntax for SQL Server, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric. Filegroup and FILESTREAM options have platform-specific restrictions described under Arguments.

DROP INDEX [ IF EXISTS ]
{ <drop_relational_or_xml_or_spatial_index> [ , ...n ]
| <drop_backward_compatible_index> [ , ...n ]
}

<drop_relational_or_xml_or_spatial_index> ::=
    index_name ON <object>
    [ WITH ( <drop_index_option> [ , ...n ] ) ]

<drop_backward_compatible_index> ::=
    [ owner_name. ] table_or_view_name.index_name

<object> ::=
{ database_name.schema_name.table_or_view_name | schema_name.table_or_view_name | table_or_view_name }

<drop_index_option> ::=
{
    <drop_clustered_index_option>
  | <low_priority_lock_wait>
}

<drop_clustered_index_option> ::=
{
    MAXDOP = max_degree_of_parallelism
  | ONLINE = { ON | OFF }
  | MOVE TO { partition_scheme_name ( column_name )
            | filegroup_name
            | "default"
            }
  | FILESTREAM_ON { partition_scheme_name
            | filestream_filegroup_name
            | "default" }
}

<low_priority_lock_wait> ::=
{
    WAIT_AT_LOW_PRIORITY ( MAX_DURATION = <time> [ MINUTES ] ,
                          ABORT_AFTER_WAIT = { NONE | SELF | BLOCKERS } )
}

Syntax for Azure Synapse Analytics.

DROP INDEX index_name ON { database_name.schema_name.table_name | schema_name.table_name | table_name }
[ ; ]

Arguments

IF EXISTS

Applies to: SQL Server 2016 (13.x) and later versions, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric.

Conditionally drops the index only if it already exists.

index_name

The name of the index to be dropped.

database_name

The name of the database.

schema_name

The name of the schema to which the table or view belongs.

table_or_view_name

The name of the table or view associated with the index. Spatial indexes are supported only on tables.

To see the details about all indexes in a database, use the sys.indexes catalog view.

Azure SQL Database supports the three-part name format: database_name.schema_name.object_name when database_name is the current database, or the database_name is tempdb and object_name starts with # or ##.

<drop_clustered_index_option>

Applies to: SQL Server 2008 (10.0.x) and later versions, SQL Database.

Controls clustered index options. For nonclustered rowstore indexes, only ONLINE = OFF is accepted from this group.

MAXDOP = max_degree_of_parallelism

Applies to: SQL Server 2008 (10.0.x) and later versions, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric.

Overrides the max degree of parallelism configuration option during the index operation. For more information, see Configure the max degree of parallelism (server configuration option). Use MAXDOP to limit the degree of parallelism and resource consumption when dropping a clustered index.

Important

MAXDOP isn't allowed for spatial indexes or XML indexes.

max_degree_of_parallelism can be one of the following values.

Value Description
1 Suppresses parallel plan generation.
>1 Limits the degree of parallelism to the specified value or less, subject to resource limits and the current workload.
0 (default) Uses the applicable server, database, and workload-group MAXDOP settings to determine the parallelism limit.

For more information, see Configure Parallel Index Operations.

Note

Parallel index operations aren't available in every edition of SQL Server. For a list of features supported by the editions in SQL Server, see Editions and supported features of SQL Server 2025.

ONLINE = ON | OFF

Applies to: SQL Server 2008 (10.0.x) and later versions, Azure SQL Database.

Specifies whether underlying tables and associated indexes are available for queries and data modification during the index operation. The default is OFF.

Starting with SQL Server 2019 (15.x), the ELEVATE_ONLINE database-scoped configuration can make an eligible single-index drop online when ONLINE isn't specified. An explicit ONLINE setting overrides this configuration.

  • ON: Queries and data modifications can continue during the main phase of the operation. Locks required to start and complete the operation can still cause blocking, including a schema modification (Sch-M) lock at completion.

  • OFF: A schema modification (Sch-M) lock prevents other sessions from accessing the table for the duration of the operation.

You can specify ONLINE = ON only when you drop a clustered index on a table. For more information, see Use options with DROP INDEX.

Note

Online index operations aren't available in every edition of SQL Server. For a list of features supported by the editions in SQL Server, see Editions and supported features of SQL Server 2025.

WAIT_AT_LOW_PRIORITY

Applies to: SQL Server 2017 (14.x) and later versions, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric.

Controls how the operation waits for locks. Specify this option directly in WITH (...), not inside the ONLINE option.

  • MAX_DURATION specifies how many minutes to wait at low priority before taking the ABORT_AFTER_WAIT action.
  • ABORT_AFTER_WAIT = NONE continues waiting at normal priority.
  • ABORT_AFTER_WAIT = SELF aborts the drop operation. MAX_DURATION must be greater than 0.
  • ABORT_AFTER_WAIT = BLOCKERS terminates the user connections blocking the operation. This action requires ALTER ANY CONNECTION permission.

The following table describes WAIT_AT_LOW_PRIORITY availability for rowstore indexes:

Index being dropped and ONLINE setting WAIT_AT_LOW_PRIORITY
Clustered index on a table, ONLINE = ON Supported, subject to online-drop restrictions
Clustered index on a table, ONLINE = OFF or omitted Not supported
Clustered index on an indexed view, ONLINE = OFF or omitted Supported
Nonclustered index on a table or indexed view, ONLINE = OFF or omitted Supported

A statement that uses WAIT_AT_LOW_PRIORITY can drop only one index. The option isn't supported for XML or spatial indexes.

MOVE TO { partition_scheme_name ( column_name ) | filegroup_name | "default" }

Applies to: SQL Server 2008 (10.0.x) and later versions. SQL Database supports "default" as the filegroup name.

Specifies a location to move the data rows that currently are in the leaf level of the clustered index. The data is moved to the new location in the form of a heap. You can specify either a partition scheme or filegroup as the new location, but the partition scheme or filegroup must already exist. MOVE TO isn't valid for indexed views or nonclustered indexes. If a partition scheme or filegroup isn't specified, the resulting table is located in the same partition scheme or filegroup as was defined for the clustered index.

If a clustered index is dropped by using MOVE TO, any nonclustered indexes on the base table are rebuilt, but they remain in their original filegroups or partition schemes. If the base table is moved to a different filegroup or partition scheme, the nonclustered indexes aren't moved to coincide with the new location of the base table (heap). Therefore, even if the nonclustered indexes were previously aligned with the clustered index, they might no longer be aligned with the heap. For more information, see Partitioned tables and indexes.

partition_scheme_name ( column_name )

Applies to: SQL Server 2008 (10.0.x) and later versions, SQL Database.

Specifies a partition scheme as the location for the resulting table. The partition scheme must already be created, by executing either CREATE PARTITION SCHEME or ALTER PARTITION SCHEME. If no location is specified and the table is partitioned, the table is included in the same partition scheme as the existing clustered index.

The column name in the scheme isn't restricted to the columns in the index definition. Any column in the base table can be specified.

filegroup_name

Applies to: SQL Server 2008 (10.0.x) and later versions.

Specifies a filegroup as the location for the resulting table. If no location is specified and the table isn't partitioned, the resulting table is included in the same filegroup as the clustered index. The filegroup must already exist.

[default]

Specifies the default location for the resulting table.

Note

In this context, default isn't a keyword. It's an identifier for the default filegroup and must be delimited, as in MOVE TO "default" or MOVE TO [default]. If "default" is specified, the QUOTED_IDENTIFIER option must be set ON for the current session. This is the default setting. For more information, see SET QUOTED_IDENTIFIER.

FILESTREAM_ON { partition_scheme_name | filestream_filegroup_name | "default" }

Applies to: SQL Server 2008 (10.0.x) and later versions.

Specifies a new location for the table's FILESTREAM data when the clustered index is dropped. You can specify a partition scheme that maps to FILESTREAM filegroups, or a FILESTREAM filegroup for a nonpartitioned heap. The partition scheme or filegroup must already exist. FILESTREAM_ON isn't valid for indexed views or nonclustered indexes, and can't be combined with ONLINE = ON. FILESTREAM isn't supported in Azure SQL Database, Azure SQL Managed Instance, or SQL database in Microsoft Fabric.

When dropping a clustered index on a partitioned table that contains FILESTREAM data, specify FILESTREAM_ON whenever you specify MOVE TO.

partition_scheme_name

Specifies a partition scheme for the FILESTREAM data. The partition scheme must already be created, by executing either CREATE PARTITION SCHEME or ALTER PARTITION SCHEME. If no location is specified and the table is partitioned, the table is included in the same partition scheme as the existing clustered index.

If you specify a partition scheme for MOVE TO, the FILESTREAM_ON partition scheme must use the same partition function. The row data scheme maps to regular filegroups; the FILESTREAM scheme maps to FILESTREAM filegroups.

filestream_filegroup_name

Specifies a FILESTREAM filegroup for FILESTREAM data. If no location is specified and the table isn't partitioned, the data is included in the default FILESTREAM filegroup.

[default]

Specifies the default location for the FILESTREAM data.

Note

In this context, default isn't a keyword. It's an identifier for the default FILESTREAM filegroup and must be delimited, as in FILESTREAM_ON "default" or FILESTREAM_ON [default]. If "default" is specified, the QUOTED_IDENTIFIER option must be ON for the current session. This is the default setting. For more information, see SET QUOTED_IDENTIFIER.

Remarks

When a nonclustered rowstore index is dropped, its definition is removed from metadata and its B-tree pages are deallocated. When a clustered rowstore index is dropped, its definition is removed from metadata, but the table's data remains in the resulting unordered heap table. Only the space that is no longer needed by the table or its remaining indexes becomes available for reuse. Deallocation can be deferred as described under Deferred deallocation.

Note

Documentation uses the term B-tree generally in reference to indexes. In rowstore indexes, the Database Engine implements a B+ tree. This does not apply to columnstore indexes or indexes on memory-optimized tables. For more information, see the SQL Server and Azure SQL index architecture and design guide.

An index can't be dropped if the filegroup in which it's located is offline or set to read-only.

When the clustered index of an indexed view is dropped, all nonclustered indexes and autocreated statistics on the same view are automatically dropped. Manually created statistics aren't dropped.

The syntax <table_or_view_name>.<index_name> is maintained for backward compatibility. An XML index or spatial index can't be dropped by using the backward compatible syntax.

Sometimes indexes are dropped and re-created to reorganize or rebuild the index, such as to apply a new fill factor value or to reorganize data after a bulk load. To do this, using ALTER INDEX is more efficient, especially for clustered indexes. ALTER INDEX REBUILD has optimizations to prevent the overhead of rebuilding the nonclustered indexes.

Deferred deallocation

When indexes with 128 extents or more are dropped, the Database Engine defers the actual page deallocations, and their associated locks, until after the transaction commits. Indexes are dropped in two separate phases: logical and physical. In the logical phase, the existing allocation units used by the index are marked for deallocation and locked until the transaction commits. In the physical phase, a background process removes the pages marked for deallocation. This means that the space released by DROP INDEX might not be available for new allocations immediately.

If accelerated database recovery is enabled, the separate logical and physical phases are used regardless of the number of extents.

Use options with DROP INDEX

You can set the following index options when you drop a clustered index: MAXDOP, ONLINE, MOVE TO, and FILESTREAM_ON.

Use MOVE TO to drop the clustered index and move the resulting table to another filegroup or partition scheme in a single transaction.

When you specify ONLINE = ON, queries and modifications can continue during the main phase of the operation, but the locks required to start and complete the drop can still cause blocking. A DROP INDEX statement that specifies ONLINE = ON can contain only one index. For more information, see ONLINE.

You can't drop a clustered rowstore index online in the following cases:

  • The index is disabled.
  • The index is on a view or a local temporary table.
  • The underlying table contains text, ntext, image, or FILESTREAM columns.

Using the ONLINE = ON and MOVE TO options requires more temporary disk space.

After a clustered index on a table is dropped, the resulting heap appears in the sys.indexes catalog view with NULL in the name column. To view the table name, join sys.indexes with sys.tables on object_id. For an example query, see example D.

On multiprocessor computers that are running SQL Server 2005 Enterprise edition or later, DROP INDEX might use more processors to perform the scan and sort operations associated with dropping the clustered index, just like other queries do. You can manually configure the number of processors that are used to run the DROP INDEX statement by specifying the MAXDOP index option. For more information, see Configure Parallel Index Operations.

When a clustered index is dropped, the corresponding heap partitions retain their data compression setting unless the partitioning scheme is modified. If the partitioning scheme is changed, all partitions are rebuilt to an uncompressed state (DATA_COMPRESSION = NONE). To drop a clustered index and change the partitioning scheme requires the following two steps:

  1. Drop the clustered index.
  2. Modify the table by using an ALTER TABLE ... REBUILD ... option specifying the compression option.

When a clustered index is dropped OFFLINE, only the upper levels of clustered indexes are removed; therefore, the operation is fast. When a clustered index is dropped ONLINE, SQL Server rebuilds the heap two times, once for step 1 and once for step 2. For more information, see Data compression.

XML indexes

Options can't be specified when you drop an XML index. Also, you can't use the <table_or_view_name>.<index_name> syntax. When a primary XML index is dropped, all associated secondary XML indexes are automatically dropped. For more information, see XML indexes (SQL Server).

Spatial indexes

Spatial indexes are supported only on tables. When you drop a spatial index, you can't specify any options or use the <table_or_view_name>..<index_name> syntax. The correct syntax is as follows:

DROP INDEX <spatial_index_name> ON <spatial_table_name>;

For more information, see Spatial Indexes Overview.

Permissions

To execute DROP INDEX, at a minimum, ALTER permission on the table or view is required. This permission is granted by default to the sysadmin fixed server role and the db_ddladmin and db_owner fixed database roles.

Examples

The code samples in this article use the AdventureWorks2025, AdventureWorksDW2025, or AdventureWorksLT2025 sample database, which you can download from the Azure Data SQL Samples Repository GitHub repository.

A. Drop an index

The following example deletes the index IX_ProductVendor_BusinessEntityID on the ProductVendor table in the AdventureWorks2025 database.

DROP INDEX IX_ProductVendor_BusinessEntityID
    ON Purchasing.ProductVendor;
GO

B. Drop multiple indexes

The following example deletes two indexes in a single transaction in the AdventureWorks2025 database.

DROP INDEX
    IX_PurchaseOrderHeader_EmployeeID ON Purchasing.PurchaseOrderHeader,
    IX_Address_StateProvinceID ON Person.Address;
GO

C. Drop a clustered index online and set the MAXDOP option

The following example deletes a clustered index with the ONLINE option set to ON and MAXDOP set to 2. Because the MOVE TO option wasn't specified, the resulting table is stored in the same filegroup as the index.

Applies to: SQL Server 2008 (10.0.x) and later versions, SQL Database.

DROP INDEX AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate
    ON Production.BillOfMaterials WITH (ONLINE = ON, MAXDOP = 2);
GO

D. Drop a clustered index online and move the table to a new filegroup

The following example deletes a clustered index online and moves the resulting table (heap) to the filegroup NewGroup by using the MOVE TO clause. The sys.indexes, sys.tables, and sys.filegroups catalog views are queried to verify the index and table placement in the filegroups before and after the move.

Applies to: SQL Server 2008 (10.0.x) and later versions, and Azure SQL Managed Instance.

Run the example in the database containing Production.BillOfMaterials. The writable filegroup NewGroup must already exist and contain a data file with enough space for the heap. For more information, see ALTER DATABASE File and Filegroup Options. If the specified clustered index doesn't exist, the table must not have another clustered index.

IF NOT EXISTS
(
    SELECT 1
    FROM sys.indexes
    WHERE object_id = OBJECT_ID(N'Production.BillOfMaterials', N'U')
      AND name = N'AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate'
)
BEGIN
    CREATE UNIQUE CLUSTERED INDEX
        AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate
        ON Production.BillOfMaterials
            (ProductAssemblyID, ComponentID, StartDate)
        ON [PRIMARY];
END;

-- Verify filegroup location of the clustered index.
SELECT t.name AS [Table Name], i.name AS [Index Name], i.type_desc,
    i.data_space_id, f.name AS [Filegroup Name]
FROM sys.indexes AS i
    JOIN sys.filegroups AS f ON i.data_space_id = f.data_space_id
    JOIN sys.tables AS t ON i.object_id = t.object_id
WHERE i.object_id = OBJECT_ID(N'Production.BillOfMaterials', N'U')
  AND i.index_id IN (0, 1);
GO

-- Drop the clustered index and move the BillOfMaterials table to
-- the Newgroup filegroup.
-- Set ONLINE = OFF to execute this example on editions other than Enterprise Edition.
DROP INDEX AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate
    ON Production.BillOfMaterials
    WITH (ONLINE = ON, MOVE TO NewGroup);

-- Verify filegroup location of the moved table.
SELECT t.name AS [Table Name], i.name AS [Index Name], i.type_desc,
    i.data_space_id, f.name AS [Filegroup Name]
FROM sys.indexes AS i
    JOIN sys.filegroups AS f ON i.data_space_id = f.data_space_id
    JOIN sys.tables AS t ON i.object_id = t.object_id
WHERE i.object_id = OBJECT_ID(N'Production.BillOfMaterials', N'U')
  AND i.index_id IN (0, 1);

E. Drop a PRIMARY KEY constraint online

Indexes that are created as the result of creating PRIMARY KEY or UNIQUE constraints can't be dropped by using DROP INDEX. They're dropped using the ALTER TABLE DROP CONSTRAINT statement. For more information, see ALTER TABLE.

The following example drops the PRIMARY KEY constraint and its clustered index on Production.TransactionHistoryArchive. If any FOREIGN KEY constraints reference this key, drop those constraints first.

-- Set ONLINE = OFF to execute this example on editions other than Enterprise Edition.
ALTER TABLE Production.TransactionHistoryArchive
DROP CONSTRAINT PK_TransactionHistoryArchive_TransactionID
WITH (ONLINE = ON);

F. Drop an XML index

The following example drops an XML index on the ProductModel table in the AdventureWorks2025 database.

DROP INDEX PXML_ProductModel_CatalogDescription
    ON Production.ProductModel;

G. Drop a clustered index on a FILESTREAM table

The following example drops a clustered index offline and moves the resulting heap and FILESTREAM data to separate partition schemes. It assumes that dbo.MyTable has a non-constraint clustered index named CX_MyTable and an integer column named PartitionColumn. The existing schemes RowDataScheme and FilestreamScheme must use the same partition function and map to regular and FILESTREAM filegroups, respectively.

Applies to: SQL Server 2008 (10.0.x) and later versions.

DROP INDEX CX_MyTable
    ON dbo.MyTable
    WITH (ONLINE = OFF,
          MOVE TO RowDataScheme (PartitionColumn),
          FILESTREAM_ON FilestreamScheme);

H. Drop an index while waiting for locks at low priority

Applies to: SQL Server 2017 (14.x) and later versions, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric.

The following example drops an existing nonclustered rowstore index. If a required lock can't be acquired within one minute, the drop operation aborts.

DROP INDEX IX_Example ON dbo.Example
WITH (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 1 MINUTES, ABORT_AFTER_WAIT = SELF));

For a clustered rowstore index on a table, specify ONLINE = ON as a separate option:

DROP INDEX CX_Example ON dbo.Example
WITH
(
    ONLINE = ON,
    WAIT_AT_LOW_PRIORITY (MAX_DURATION = 1 MINUTES, ABORT_AFTER_WAIT = SELF)
);