Moving all non-clustered indexes to another filegroup in SQL Server

后端 未结 3 1857
醉梦人生
醉梦人生 2021-01-31 20:35

In SQL Server 2008, I want to move ALL non-clustered indexes in a DB to a secondary filegroup. What\'s the easiest way to do this?

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 21:08

    Update: This thing will take long time to do step 2 manually if you are using MS SQL Server manager 2008R2 or earlier. I used sql server manager 2014, so it works well (because the way it export the drop and create index is easy to modify) I tried to run script in SQL server 2014 and got some issue, I'm too lazy to detect the problems, SO I come up with another solution that not depend on the version of SQL server you are running.

    1. Export your index (with drop and create)

    2.Update your script, remove all things related to drop create tables, keep the thing belong to indexs. and Replace your original index with the new index (in my case, I replace ON [PRIMARY] by ON [SECONDARY] [enter image description here]5

    1. Run script! And wait until it done.

    (You may want to save the script to run in some others environment).

提交回复
热议问题