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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Run this updated script to create a stored procedure called
MoveIndexToFileGroup. This procedure moves all the non-clustered indexes on a table to a specified file group. It even supports theINCLUDEcolumns that some other scripts do not. In addition, it will not rebuild or move an index that is already on the desired file group. Once you’ve created the procedure, call it like this:To create a script that will run this for each table in your database, switch your query output to text, and run this:
Please refer to the original blog for more details. I did not write this procedure, but updated it according to the blog’s responses and confirmed it works on both SQL Server 2005 and 2008.
Updates
IGNORE_DUP_KEYoption on. No fix for this yet.