How to... Change a Filegroup for an Existing Table

  • Hi,

    What is the syntax to change the filegroup for an existing table object and index? I was also thinking of using "sp_msforeachtable" to do multiple objects.

    Thanks. Jeff

    Many thanks. Jeff

  • CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name

        ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )

    [ WITH < index_option > [ ,...n] ]

    [ ON filegroup ]

    For moving existing nonclustered index, You have to drop the index and recreate it in new filegroup.

    If you want to move the table into new filegroup, create the clustered index on the table in the new filegroup. You can drop the clustered index later if you don't need clustered for the table.

  • Hi, thanks. But I'm not creating new tables ... I want to ALTER the existing tables ... ???

    Many thanks. Jeff

  • ... and you are if you recreate the clustered index as Allen Cui mentioned above!


    * Noel

  • Is ther not a statement like:

    ALTER TABLE MyTable ON [NewFileGroup]

    ??

    Many thanks. Jeff

  • No.

    Alter table modifies a table definition by altering, adding, or dropping columns and constraints, or by disabling or enabling constraints and triggers. See BOL for complete syntax.

  • Cant use alter table or anything simple. I assume you know you can do it via design table in Ent Mgr

  • Using EM? I was hoping for something similar to ORACLE, which allows you to move objects to new filegroups/tablespaces using the ALTER syntax for the given object type ie: table/index. Maybe Microsoft is changing this???

    Thanks everyone for your help ...

    Many thanks. Jeff

  • If you simply recreate the clustered index of a table on a different filegroup it will move the whole set of data in that table to the new filegroup? That makes sense but it seems too easy...

  • Would you like it better when it was way more complicated?

    The leaf level of a clustered index is the actual table data. So when you recreate it on another filegroup you actually move the data there.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply