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 |
|
|
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric |
[!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:
-
To rename an index, using:
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.
Requires ALTER permission on the index.
-
In Object Explorer, click the plus sign to expand the database that contains the table on which you want to rename an index.
-
Click the plus sign to expand the Tables folder.
-
Right-click the table on which you want to rename an index and select Design.
-
On the Table Designer menu, click Indexes/Keys.
-
Select the index you want to rename in the Selected Primary/Unique Key or Index text box.
-
In the grid, click Name and type a new name into the text box.
-
Click Close.
-
On the File menu, click Savetable_name.
-
In Object Explorer, click the plus sign to expand the database that contains the table on which you want to rename an index.
-
Click the plus sign to expand the Tables folder.
-
Click the plus sign to expand the table on which you want to rename an index.
-
Click the plus sign to expand the Indexes folder.
-
Right-click the index you want to rename and select Rename.
-
Type the index's new name and press Enter.
-
In Object Explorer, connect to an instance of [!INCLUDEssDE].
-
On the Standard bar, click New Query.
-
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).