Move an Existing Index to a Different Filegroup
This topic describes how to move an existing index from its current filegroup to a different filegroup in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL.
In This Topic
-
Before you begin:
-
To move an existing index to a different filegroup, using:
Limitations and Restrictions
-
If a table has a clustered index, moving the clustered index to a new filegroup moves the table to that filegroup.
-
You cannot move indexes created using a UNIQUE or PRIMARY KEY constraint using Management Studio. To move these indexes use the CREATE INDEX statement with the (DROP_EXISTING=ON) option in Transact-SQL.
Security
To move an existing index to a different filegroup using Table Designer
-
In Object Explorer, click the plus sign to expand the database that contains the table containing the index that you want to move.
-
Click the plus sign to expand the Tables folder.
-
Right-click the table containing the index that you want to move and select Design.
-
On the Table Designer menu, click Indexes/Keys.
-
Select the index that you want to move.
-
In the main grid, expand Data Space Specification.
-
Select Filegroup or Partition Scheme Name and select from the list the filegroup or partition scheme to where you want to move the index.
-
Click Close.
-
On the File menu, select Save table_name.
To move an existing index to a different filegroup in Object Explorer
-
In Object Explorer, click the plus sign to expand the database that contains the table containing the index that you want to move.
-
Click the plus sign to expand the Tables folder.
-
Click the plus sign to expand the table containing the index that you want to move.
-
Click the plus sign to expand the Indexes folder.
-
Right-click the index that you want to move and select Properties.
-
Under Select a page, select Storage.
-
Select the filegroup in which to move the index.
If the table or index is partitioned, select the partition scheme in which to move the index. For more information about partitioned indexes, see Partitioned Tables and Indexes.
If you are moving a clustered index, you can use online processing. Online processing allows concurrent user access to the underlying data and to nonclustered indexes during the index operation. For more information, see Perform Index Operations Online.
On multiprocessor computers using SQL Server 2012, you can configure the number of processors used to execute the index statement by specifying a maximum degree of parallelism value. The Parallel indexed operations feature is not available in every edition of SQL Server. For a list of features that are supported by the editions of SQL Server, see Features Supported by the Editions of SQL Server 2012 (http://go.microsoft.com/fwlink/?linkid=232473). For more information about Parallel indexed operations, see Configure Parallel Index Operations.
-
Click OK.
The following information is available on the Storage page of the Index Properties – index_name dialog box:
To move an existing index to a different filegroup
-
In Object Explorer, connect to an instance of Database Engine.
-
On the Standard bar, click New Query.
-
Copy and paste the following example into the query window and click Execute.
USE AdventureWorks2012; GO -- Creates the TransactionsFG1 filegroup on the AdventureWorks2012 database ALTER DATABASE AdventureWorks2012 ADD FILEGROUP TransactionsFG1; GO /* Adds the TransactionsFG1dat3 file to the TransactionsFG1 filegroup. Please note that you will have to change the filename parameter in this statement to execute it without errors. */ ALTER DATABASE AdventureWorks2012 ADD FILE ( NAME = TransactionsFG1dat3, FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL11\MSSQL\DATA\TransactionsFG1dat3.ndf', SIZE = 5MB, MAXSIZE = 100MB, FILEGROWTH = 5MB ) TO FILEGROUP TransactionsFG1; GO /*Creates the IX_Employee_OrganizationLevel_OrganizationNode index on the TransactionsPS1 filegroup and drops the original IX_Employee_OrganizationLevel_OrganizationNode index. */ CREATE NONCLUSTERED INDEX IX_Employee_OrganizationLevel_OrganizationNode ON HumanResources.Employee (OrganizationLevel, OrganizationNode) WITH (DROP_EXISTING = ON) ON TransactionsFG1; GO
For more information, see CREATE INDEX (Transact-SQL).