Moving a table to another filegroup

by Syska 9. June 2010 16:10

So, how does one move a table to another filegroup.

Say I have the following table:

CREATE TABLE [dbo].[Tests](
    [TestID] [int] NOT NULL,
    [TestInt] [int] NOT NULL,
    [TestBigInt] [bigint] NOT NULL,
 CONSTRAINT [PK_Tests] PRIMARY KEY CLUSTERED 
(
    [TestID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

Since tables are always stored with the clustered index. Moving the clustered index, also moves the table. So if we want to move the table, we can recreate the CLUSTERED index on another storage group. Here we are moving from “PRIMARY” to “PRIMARY2”.

CREATE UNIQUE CLUSTERED INDEX PK_Tests
   ON dbo.Tests(TestID)
   WITH DROP_EXISTING
ON [PRIMARY2]

This can also be done when the table is online and is also moving the indexes. There are some performance diff if you are moving the table while its still online, so consider if its worth the extra overhead.

You can extend the relation index options with the create index command like this, to move it while its still online.

CREATE UNIQUE CLUSTERED INDEX PK_Tests
   ON dbo.Tests(TestID)
   WITH (DROP_EXISTING = ON, ONLINE = ON)
ON [PRIMARY2]

Tags: ,

MSSQL

Comments

6/25/2010 8:06:21 PM #

make money

Oh wow, nice stuff man, but one question though. How or where did you discover all this info from ?

make money United States |

6/28/2010 3:20:54 PM #

Blogging to the Bank 4.0

From all of the blogging stuff I studied what I learned the most was Blogging to the Bank - hands down

Blogging to the Bank 4.0 United States |

6/28/2010 3:29:57 PM #

SaraGreenwich

I'm excited to be finally posting online after all these years. There really is no mystery about it, is there? I just dropped by your blog and had to write. I'm a recent college grad, journalism major if you must know, and I love the art of photography. I've got my website up but it's nothing to brag about yet. None of my stuff's been posted. Soon as I figure out how to do that, I'll spend the afternoon posting my best pictures. anyhow just thought I'd drop a line. I hope to return with more substantial stuff, stuff you can actually use. SPG

SaraGreenwich United States |

7/1/2010 3:33:06 AM #

Karl Ibach

I can never locate golf clubs that I'm pleased with.  Seems like I like them on the first round but later I'm back to cussing them!  I'm using Pings right now and they seem to be good but I've only cut my score by one stroke.  Maybe it's my swing!

Karl Ibach United States |

7/6/2010 5:46:44 AM #

Cedrick Ran

Just curious will need to you knew something else about the big blogengine update that�s coming up soon? I�m trying to reach out to over webmasters to look for out what they know for the reason that Google hasn�t indexed whatever new on it for awhile.

Cedrick Ran Honduras |

7/6/2010 5:46:53 AM #

Cristen Jamal

Just curious once you happen to knew something else about the significant blogengine update that�s coming up soon? I�m attempting to reach out to over webmasters to discover out what they know due to the fact Google hasn�t indexed whatever new on it for awhile.

Cristen Jamal Puerto Rico |

7/9/2010 1:45:30 AM #

table magician

Well written, I believe this only scratches the surface.

table magician United States |

7/11/2010 4:07:07 AM #

close up magician

It's crazy this gets written about so little, I'm sure the demand is there.

close up magician United States |

7/13/2010 2:21:15 AM #

table magician

Extremely inspiring. It's amazing what can be done when we put our minds to it.

table magician United States |

7/14/2010 9:31:16 AM #

buy neopoints

I've been lurking on and away for a while, so I guess I should post at least one time here. I don't in truth have much to say because I got most of my information from other places, but I genuinely liked reading your entries anyway.

buy neopoints United States |

7/15/2010 9:05:25 AM #

Richard Alan

What I love about blogs is the Honesty in them all, the fact that you can get the true attitued of people to come out, and know when you have an article that touches people.  Lawrence Williams  www.trybw.com  Fort Myers, Naples, Bonita,Cape Coral  Computer Laptop Repair Service and Virus Removal

Richard Alan United States |

7/18/2010 7:14:14 PM #

electronic cigarette

Ha, can't say you're wrong. Just need to get my head around this.

electronic cigarette United States |

7/26/2010 10:01:36 AM #

iPhone information

Ha, can't say you're wrong. Just need to get my head around this.

iPhone information United States |

8/1/2010 11:38:29 PM #

Pete Salaiz

You are probably sick of hearing comments like this, but you have got a really well written blog. Keep up the the great blog.  

Pete Salaiz United States |

8/2/2010 6:30:20 PM #

Technology & Gadget

Always enjoy reading spot on articles by an author who is obviously knowledgeable on their chosen subject….Now is the perfect time (summer now)to spend some money to grab those fancy dress and accessories! LOL….. Keep up the great work, see you next time.

Technology & Gadget Vietnam |

8/3/2010 2:38:56 AM #

Davis Alexion

You have a really interesting blog. Too many blogs that I see these days don't really offer anything that I'm interested in, but I am most definately interested in this blog. Just thought that I would post and let you know.

Davis Alexion United States |

8/3/2010 11:19:21 AM #

flip camera

Cute videos and a thorough evaluation I have noticed about Flip. A year ago, I was thrilled to release a video cast and trying to find a mini cam suits my needs. In the end of the day I bought a Sanyo Xacti HD1000 for more professional stuff but nevertheless looking for a tiny device I can carry around.I received my MinoHD for Xmas and the video is not jittery or pixelated on mine, regardless of the lighting conditions. Would it be possible the firmware on your MinoHD is an older version?

flip camera United States |

8/4/2010 2:25:04 AM #

Click Here

This sort of info should be valued by everybody - it's something which i think we can all draw upon. I very much like the theme you're utilizing right here which I believe is wordpress is not it? I have been looking close to for some thing simular but have yet to find some thing suitable for my site. I looked in the link in your footer and will attempt and download a copy of it for myself - thanks.

Click Here United States |

8/5/2010 5:51:52 PM #

Dexter Zettel

You have a really interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would pass that message on.

Dexter Zettel United States |

8/8/2010 4:45:40 PM #

get a girl

Thanks for making the sincere attempt to divulge this. I feel fairly strong about it and would like to learn more. If it's allright, as you gain more in depth knowledge, would you mind adding more articles similar to this one with more information? It would be so helpful and useful for me and my co-workers.

get a girl United States |

Comments are closed

About the brain

Mikael SyskaMikael Syska

Student at the Engineering College of Aarhus.

Microsoft Student Partner ( MSP )

On this blog I will primarily write about .NET, MSSQL & projects I'm working on ... and of course there will some off topic posts :-)