Skip to content

Latest commit

 

History

History
102 lines (63 loc) · 4.05 KB

rename-indexes.md

File metadata and controls

102 lines (63 loc) · 4.05 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic ms.custom helpviewer_keywords monikerRange
Rename Indexes
Rename Indexes
MikeRayMSFT
mikeray
02/17/2017
sql
table-view-index
how-to
ignite-2024
renaming indexes
index names [SQL Server]
indexes [SQL Server], renaming
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric

Rename Indexes

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

This topic describes how to rename an index in [!INCLUDEssnoversion] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql]. Renaming an index replaces the current index name with the new name that you provide. The specified name must be unique within the table or view. For example, two tables can have an index named XPK_1, but the same table cannot have two indexes named XPK_1. You cannot create an index with the same name as an existing disabled index. Renaming an index does not cause the index to be rebuilt.

In This Topic

Before You Begin

Limitations and Restrictions

When you create a PRIMARY KEY or UNIQUE constraint on a table, an index with the same name as the constraint is automatically created for the table. Because index names must be unique within the table, you cannot create or rename an index to have the same name as an existing PRIMARY KEY or UNIQUE constraint on the table.

Security

Permissions

Requires ALTER permission on the index.

Using SQL Server Management Studio

To rename an index by using the Table Designer

  1. In Object Explorer, click the plus sign to expand the database that contains the table on which you want to rename an index.

  2. Click the plus sign to expand the Tables folder.

  3. Right-click the table on which you want to rename an index and select Design.

  4. On the Table Designer menu, click Indexes/Keys.

  5. Select the index you want to rename in the Selected Primary/Unique Key or Index text box.

  6. In the grid, click Name and type a new name into the text box.

  7. Click Close.

  8. On the File menu, click Savetable_name.

To rename an index by using Object Explorer

  1. In Object Explorer, click the plus sign to expand the database that contains the table on which you want to rename an index.

  2. Click the plus sign to expand the Tables folder.

  3. Click the plus sign to expand the table on which you want to rename an index.

  4. Click the plus sign to expand the Indexes folder.

  5. Right-click the index you want to rename and select Rename.

  6. Type the index's new name and press Enter.

Using Transact-SQL

To rename an index

  1. In Object Explorer, connect to an instance of [!INCLUDEssDE].

  2. On the Standard bar, click New Query.

  3. Copy and paste the following example into the query window and click Execute.

    USE AdventureWorks2022;  
    GO  
    --Renames the IX_ProductVendor_VendorID index on the Purchasing.ProductVendor table to IX_VendorID.   
    
    EXEC sp_rename N'Purchasing.ProductVendor.IX_ProductVendor_VendorID', N'IX_VendorID', N'INDEX';   
    GO  
    

For more information, see sp_rename (Transact-SQL).