question

Inquisitivo avatar image
Inquisitivo asked

Move all DB indexes with page_count of 10000 or less to new filegroup

Hello,

I am already able to move nonclustered, nonunique indexes with page count of 10,000 or less to secondary filegroup manually one by one. I have to move 1,100 of them.

I am looking for a way to do this programmatically either in groups or all in one shot. I'm using SQL Server 2017.

Thanks in advance

sqlserverfilegroupnonclustered-indexmove
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jeff Moden avatar image
Jeff Moden answered

You need to search the Internet for something that will make the CREATE INDEX statement for the indexes and modify that to change them to recreate them using the WITH(DROP_EXISTING = ON) option to move them.

This one was posted in 2016... I can't get to the actual link Kenra posted that has the script because of the security limitations on the box I'm currently working on...

https://www.littlekendra.com/2016/05/05/how-to-script-out-indexes-from-sql-server/

As with all else, it and anything you find on the internet wasn't actually written by Microsoft and, with that I'll say, "Caveat Emptor".

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.