반응형
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
반응형
'DB > MSSQL' 카테고리의 다른 글
Some tips for using full-text search in SQL Server 2016 (1) | 2020.06.23 |
---|---|
[MSSQL] WHERE CASE WHEN 조건절에 조건문 (0) | 2020.06.17 |
MSSQL) Full Text Search : Indexing 진행 현황 확인하기 (0) | 2020.06.12 |
MSSQL) Full Text Searching - 전체 텍스트 인덱스 관리 (0) | 2020.06.12 |
MSSQL) Full Text Search(FREETEXTABLE) 관리 및 데이터 쿼리 모음 (0) | 2020.06.12 |