Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2002
    Location
    BH - MG - BRAZIL
    Posts
    13

    Unanswered: Change Table's FileGroup

    Hi!!!

    I would like change table's filegroup.

    How can I do by script?

    Thank you.

    Bye.

  2. #2
    Join Date
    Apr 2003
    Posts
    30
    I think you may have to create a new table in different filegroup, and transfer the data to this new table and create all the relationships. Then
    finally drop the old table and rename the new table to the old one.

    Anybody has better way?

  3. #3
    Join Date
    Dec 2002
    Posts
    1,245
    The only way of doing this (of which I am aware) is to drop and re-create the table using the ON option.

    You might try:
    Code:
    CREATE MyTable_Temp (
      Foo varchar(10) NOT NULL, 
      Bar int NULL
    ) ON [MyFileGroup]
    
    INSERT INTO MyTable_Temp (Foo, Bar)
    SELECT Foo, Bar 
    FROM MyTable
    
    DROP TABLE MyTable
    
    sp_rename N'MyTable', N'MyTableTemp'
    Note that this example does not include any constraints, indexes, dependent objects or anything else. Actual mileage may vary. Wear your seatbelt.

    Regards,

    Hugh Scott

  4. #4
    Join Date
    Apr 2003
    Location
    SC, USA
    Posts
    51
    It's true that those are the only ways to do it by script. However, if you only need to do it for a few tables, it may be quicker to use Enterprise Manager instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •