반응형

1) Drop the existing clustered index first (IX_TableX_FieldB):

DROP INDEX TableX.IX_TableX_FieldB

2) Create a (temporary) UNIQUE constraint on the unique fields referenced in the primary key

ALTER TABLE TableX
ADD CONSTRAINT UQ_TableX UNIQUE(FieldA)

3) Drop the PRIMARY KEY

ALTER TABLE TableX
DROP CONSTRAINT PK_TableX

4) Recreate the PRIMARY KEY as CLUSTERED

ALTER TABLE TableX
ADD CONSTRAINT PK_TableX PRIMARY KEY CLUSTERED(FieldA)

5) Drop the temporary UNIQUE constraint

ALTER TABLE TableX
DROP CONSTRAINT UQ_TableX

6) Add the IX_TableX_FieldB back on as NONCLUSTERED

CREATE NONCLUSTERED INDEX IX_TableX_FieldB ON TableX(FieldB)

출처 : https://stackoverflow.com/questions/2297355/change-a-primary-key-from-nonclustered-to-clustered

반응형

+ Recent posts