Need to convert PK to clustered but it is referenced by a FK

  • Hi all.

    I have a heap that has a non-clustered index and it is a primary key. I need to convert it to a clustered one. The problem is that it is referenced by a foreign key from another table. For now, I am doing 4 steps:

    1. Drop FK.

    2. Drop PK.

    3. Recreate PK (as clustered)

    4. Recreate FK

    But is there a more elegant solution? I tried to manipulate with drop_existing, etc, but so far nothing like this works. What I need is only to change my PK to clustered.

    Thanks.

  • SQL Guy 1 (5/28/2014)


    1. Drop FK.

    2. Drop PK.

    3. Recreate PK (as clustered)

    4. Recreate FK

    Yup. Assuming there's only one foreign key that is.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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