How can I move a table to another filegroup in MS SQL Server?

后端 未结 8 1985
星月不相逢
星月不相逢 2020-12-07 13:04

I have SQL Server 2008 Ent and OLTP database with two big tables. How I can move these tables to another filegroup without service int

相关标签:
8条回答
  • 2020-12-07 13:48

    I think these steps are very simple and straight forward to move any table to a different file group (through Management Studio):

    • Move all non-clustered indexes to a new file group simply by changing the FileGroup property for each indexes

    • Change your cluster index to non-cluster and change its file group simply (like the previous step)

    • Add a new temporary cluster index with "new file group" through this command(or via IDE) :

         CREATE CLUSTERED INDEX [PK_temp]
      ON YOURTABLE([Id])
        ON NEWFILEGROUP
      

      (the above command causes to move all data to new file group)

    • Delete the above temporary PK (when it does its job prefectly!)

    • Change back your main cluster index to be cluster index again (through IDE again)

    The benefit of above steps is not need to drop existing FK relationships. Also using IDE prevents losing data in error conditions.

    NOTE : be sure Disk Quota is not enabled for your FileGroup or set it ocrrectly. Otherwise you get you "filegroup is full" exception!

    0 讨论(0)
  • 2020-12-07 13:51

    This excerpt from SQL Server Books Online says it all: "Because the leaf level of a clustered index and the data pages are the same by definition, creating a clustered index and using the ON partition_scheme_name or ON filegroup_name clause effectively moves a table from the filegroup on which the table was created to the new partition scheme or filegroup." (Source - http://msdn.microsoft.com/en-us/library/ms188783.aspx) from (http://www.mssqltips.com/sqlservertip/2442/move-data-between-sql-server-database-filegroups/)

    as already said by other friends like accepted answer by marc_s following is the screenshot gives you another way to do it using SSMS GUI.

    please note that you can move to another filegroup easily of the index property in storage tab enter image description here

    0 讨论(0)
提交回复
热议问题