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 9180873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:09:22+00:00 2026-06-17T18:09:22+00:00

I have multiple indexed views that I want to move from the primary filegroup

  • 0

I have multiple indexed views that I want to move from the primary filegroup into another filegroup, with minimal impact on performance. How can I accomplish 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-06-17T18:09:24+00:00Added an answer on June 17, 2026 at 6:09 pm

    This should generate the script to do what you want, including both the clustered and any non-clustered indexes. I’ve added the ONLINE = ON option to minimize impact to existing workload but, in theory anyway, your indexed views shouldn’t be huge and so shouldn’t have any drastic impact. Of course this option is only available in Enterprise Edition, and the script handles that. If you can’t do it online you’ll certainly want to test the impact with a simulated workload (and you’ll want to test this operation in a test environment first in any case). And you are best off scheduling this work for a relative downtime or, ideally, a maintenance window.

    DECLARE @opt NVARCHAR(13),  @sql NVARCHAR(MAX), @fg  NVARCHAR(128);
    
    SELECT @fg  = N'OtherFileGroupName', -- please fix this
      @sql = N'', 
      @opt = CASE WHEN CONVERT(NVARCHAR(32), SERVERPROPERTY('Edition')) 
        LIKE N'Enterprise%' THEN N', ONLINE = ON' ELSE N'' END;
    
    SELECT @sql = @sql + N'
      CREATE ' + CASE WHEN i.index_id = 1 
        THEN 'UNIQUE CLUSTERED' 
        ELSE '' END
      + ' INDEX ' + QUOTENAME(i.name) 
      + ' ON ' + QUOTENAME(SCHEMA_NAME(v.[schema_id]))
      + '.' + QUOTENAME(v.name) 
      + '(' + STUFF((SELECT ',' + QUOTENAME(c.name)
        FROM sys.columns AS c
        INNER JOIN sys.index_columns AS ic 
        ON c.[object_id] = ic.[object_id]
        AND c.column_id = ic.column_id
        WHERE c.[object_id] = v.[object_id]
        AND ic.index_id = i.index_id
        FOR XML PATH, 
        TYPE).value(N'./text()[1]', N'nvarchar(max)'),1,1,N'')
      + ') 
      WITH (DROP_EXISTING = ON' + @opt + ')
      ON ' + QUOTENAME(@fg) + ';'
    FROM sys.views AS v
    INNER JOIN sys.indexes AS i
    ON v.[object_id] = i.[object_id]
    ORDER BY i.index_id;
    
    SELECT @sql;
    -- EXEC sp_executesql @sql;
    

    This should yield a script like:

    CREATE UNIQUE CLUSTERED INDEX [x] 
      ON [dbo].[splunge_view]([id])
      WITH (DROP_EXISTING = ON, ONLINE = ON)
      ON [OtherFileGroupName];
    
    CREATE  INDEX [y] 
      ON [dbo].[splunge_view]([c],[id]) 
      WITH (DROP_EXISTING = ON, ONLINE = ON)
      ON [OtherFileGroupName];
    
    ...
    

    When you’re happy with the SELECT output (works best in results to text mode, but still is limited to 8K there and only if you change the setting in tools / options), uncomment the EXEC. But again, in a test environment first!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple tables that data can be queried from with joins. In regards
If have multiple indexed models that have a verification level which need to be
I have an NSTableView that I want to load it's value from an NSArrayController.
I have multiple forms for lots of products on my page and want to
I have multiple domains on my server. I want to redirect all of them
I have an app that loads records from a binary log file and displays
I have a website that has multiple languages. The way this is set up
We have a requirement to delete rows in the order of millions from multiple
I have a number of schema bound views that I'd like to add indexes
I have to work with multiple SQL Server tables that generally look like this:

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.