Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

How can I move a clustered primary key to a new filegroup? I already have found a possible "algorithm" but it is horribly inefficient:

  1. Drop non-clustered indexed (requires them to be resorted and rebuilt)
  2. Drop clustered index (requires the whole table to be resorted)
  3. Create new primary key constraint (huge sort operation)
  4. Create all non-clustered indexes (sorting and writing required)

Is there a more efficient way? This is horribly inefficient and will take a long time as the table is 50GB in size on a weak server.

Isn't there a way to skip all of these and just do a rebuild on a new filegroup? That would not require any sorting of data.

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted
CREATE UNIQUE CLUSTERED INDEX Your_PK_Name
    ON YourTable(YourColumnList)
WITH (DROP_EXISTING =  ON )
ON [YourOtherFileGroup]

This preserves the logical PK property despite it not being mentioned in the syntax.

share|improve this answer
    
I just confirmed this to work. It moves the CI to the new filegroup while not requiring sorting. It also keeps the existing NCI's. Thank you! –  usr Nov 18 '12 at 13:44
    
thanks for the info Martin. –  Craig Efrein Nov 18 '12 at 13:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.