Moving an index to a different filegroup

This recipe illustrates how to move indexes to a different filegroup.

Getting ready

Using the TestDB database, or any database of your choice, let's create a table called Student with a clustered primary key.

Open SQL Server Management Studio and execute the following code:

USE TestDB GO -- this table is going to be stored to -- the default filegroup IF OBJECT_ID('Student') IS NOT NULL DROP TABLE Student GO CREATE TABLE Student ( ID INT IDENTITY(1,1) NOT NULL, FName VARCHAR(50), CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED ([ID] ASC) ) GO -- insert some sample data -- nothing fancy, every student will be called Joe for now :) INSERT INTO Student(FName) VALUES('Joe') GO 20 INSERT INTO Student(FName) SELECT ...

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.