Renaming of Index and Primary Key

  • Below is the create table script. When created Primary Key name and Index name are the same. If I change the name of Index then Primary Key name will also change to same and vice versa. How do I change the name either of objects without affecting each other?

    CREATE TABLE dbo.[BackupConfigtest](

    [ID] [INT] IDENTITY(1,1) NOT NULL,

    [DatabaseName] [VARCHAR](128) NOT NULL,

    [Enabled] [BIT] NOT NULL,

    CONSTRAINT [PK_BackupConfigtest_ID] PRIMARY KEY NONCLUSTERED

    (

    [ID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

    ) ON [PRIMARY]

    GO

    For Example:

    Right click on Index - Rename - "IX_BackupConfigtest_ID" then Primary Key name will change to same.

    After that rename Primary Key as "PK_BackupConfigtest_ID" then Index name will change to same.

    How do I achieve renaming of Primary Key and Index object without affecting each other?

    FYI...I have used sp_rename and it does the same.

    Thanks in advance.

  • monilps (5/9/2016)


    Below is the create table script. When created Primary Key name and Index name are the same. If I change the name of Index then Primary Key name will also change to same and vice versa. How do I change the name either of objects without affecting each other?

    CREATE TABLE dbo.[BackupConfigtest](

    [ID] [INT] IDENTITY(1,1) NOT NULL,

    [DatabaseName] [VARCHAR](128) NOT NULL,

    [Enabled] [BIT] NOT NULL,

    CONSTRAINT [PK_BackupConfigtest_ID] PRIMARY KEY NONCLUSTERED

    (

    [ID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

    ) ON [PRIMARY]

    GO

    For Example:

    Right click on Index - Rename - "IX_BackupConfigtest_ID" then Primary Key name will change to same.

    After that rename Primary Key as "PK_BackupConfigtest_ID" then Index name will change to same.

    How do I achieve renaming of Primary Key and Index object without affecting each other?

    FYI...I have used sp_rename and it does the same.

    Thanks in advance.

    Can you supply the DDL for IX_BackupConfigtest_ID index?

    I have to say, I created a table and key using your script, added an index named IX_BackupConfigtest_ID, and I cannot duplicate this.

    Did you try to drop both the key and the index, and then re-create one at a time with the new name?

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply