Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4572776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:41:37+00:00 2026-05-21T19:41:37+00:00

In SQL Server 2008, I want to move ALL non-clustered indexes in a DB

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:41:38+00:00Added an answer on May 21, 2026 at 7:41 pm

    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 the INCLUDE columns 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:

    EXEC MoveIndexToFileGroup @DBName = '<your database name>',
                              @SchemaName = '<schema name that defaults to dbo>',
                              @ObjectNameList = '<a table or list of tables>',
                              @IndexName = '<an index or NULL for all of them>',
                              @FileGroupName = '<the target file group>';
    

    To create a script that will run this for each table in your database, switch your query output to text, and run this:

    SELECT 'EXEC MoveIndexToFileGroup '''
        +TABLE_CATALOG+''','''
        +TABLE_SCHEMA+''','''
        +TABLE_NAME+''',NULL,''the target file group'';'
        +char(13)+char(10)
        +'GO'+char(13)+char(10)
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE = 'BASE TABLE'
    ORDER BY TABLE_SCHEMA, TABLE_NAME;
    

    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

    1. @psteffek modified the script to work on SQL Server 2012. I merged his changes.
    2. The procedure fails when your table has the IGNORE_DUP_KEY option on. No fix for this yet.
    3. @srutzky pointed out the procedure does not guarantee to preserve the order of an index and made suggestions on how to fix it. I updated the procedure accordingly.
    4. ojiNY noted the procedure left out index filters (for compatibility with SQL 2005). Per his suggestion, I added them back in.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL Server 2008 Profiler always profiles all databases. I want to restrict profiling or
This is on SQL Server 2008. I have several columns I want to convert
I installed SQL Server 2008 R2. Now I want to install BIDS in this
Running this query in sql server 2008 now, but soon plan to move it
I need to create an entirely new Sql Server 2008 database and want to
In SQL Server 2008, I want to represent an integer as a 3-character string
In SQL Server 2008, I want to export the result of a stored procedure
In SQL Server 2008: I have one table, and I want to do something
I am using SQL Server 2008 Enterprise version. I want to know if I
I want to compare records between 2 databases on my SQL 2008 Server. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.