Skip to content

Latest commit

 

History

History
93 lines (60 loc) · 4.7 KB

perform-index-operations-online.md

File metadata and controls

93 lines (60 loc) · 4.7 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic ms.custom helpviewer_keywords monikerRange
Perform index operations online
Create, rebuild, or drop indexes online in the SQL Server Database Engine.
MikeRayMSFT
mikeray
randolphwest
02/17/2025
sql
table-view-index
how-to
ignite-2024
index online operations [SQL Server]
online index operations
ONLINE option
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric

Perform index operations online

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB]

This article describes how to create, rebuild, or drop indexes online using [!INCLUDE ssManStudioFull] or [!INCLUDE tsql]. The ONLINE option allows concurrent user access to the underlying table or clustered index data and any associated nonclustered indexes during these index operations. For example, while a clustered index is being rebuilt by one user, that user and others can continue to update and query the underlying data.

When you perform data definition language (DDL) operations offline, such as building or rebuilding a clustered index, these operations hold exclusive (X) locks on the underlying data and associated indexes. This prevents modifications and queries to the underlying data until the index operation is complete.

Note

Index rebuild commands might hold exclusive locks on clustered indexes after a large object column is dropped from a table, even when performed online.

The ONLINE option is available in the following [!INCLUDE tsql] statements.

For limitations and restrictions concerning creating, rebuilding, or dropping indexes online, see Guidelines for online index operations.

To use resumable index operations, an index operation must be performed online. For more information, see Resumable index considerations.

Supported platforms

Online index operations aren't available in every edition of [!INCLUDE ssNoVersion]. For more information, see Editions and supported features of SQL Server 2022.

Online index operations are available in [!INCLUDE ssazure-sqldb] and [!INCLUDE ssazuremi-md].

Permissions

Requires the ALTER permission on the table or view.

Use SQL Server Management Studio

  1. In Object Explorer, expand the database that contains the table on which you want to rebuild an index online.

  2. Expand the Tables folder.

  3. Expand the table on which you want to rebuild an index online.

  4. Expand the Indexes folder.

  5. Use the context menu for the index that you want to rebuild online and select Properties.

  6. Under Select a page, select Options.

  7. Select Allow online DML processing, and then select True from the list.

  8. Select OK.

  9. Use the context menu for the index that you want to rebuild online and select Rebuild.

  10. In the Rebuild Indexes dialog box, verify that the correct index is in the Indexes to rebuild grid and select OK.

Use Transact-SQL

The following example rebuilds an existing online index in the AdventureWorks sample database.

ALTER INDEX AK_Employee_NationalIDNumber
    ON HumanResources.Employee
    REBUILD WITH (ONLINE = ON);

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.

:::code language="sql" source="codesnippet/tsql/perform-index-operations_1.sql":::

For more information, see ALTER INDEX (Transact-SQL).

Related content