September 26, 2003 at 3:01 pm
I know you can move a table to a different filegroup in Enterprise Manager. How can this be done via a sql statement? I have numerous tables to move and doing so through EM will take forever.
September 26, 2003 at 4:19 pm
quote:
I know you can move a table to a different filegroup in Enterprise Manager. How can this be done via a sql statement? I have numerous tables to move and doing so through EM will take forever.
Recreate the clustered index; if you use the DROP_EXISTING option, it will be faster:
CREATE CLUSTERED INDEX Employee_Ind ON Employee(LName,FName,Minit)
WITH DROP_EXISTING
ON SECONDARY
--Jonathan
--Jonathan
October 6, 2003 at 1:37 pm
What if there is no clustered index on the table?? Is there any other way to accomplish this?
October 6, 2003 at 2:07 pm
quote:
What if there is no clustered index on the table?? Is there any other way to accomplish this?
Create a clustered index on the desired filegroup. Then drop that index.
--Jonathan
--Jonathan
October 6, 2003 at 2:15 pm
Is there no other way?? I've got 170 tables and 108 indexes to move. Creating a dummy index and then dropping it will take just as long, if not longer, than doing the moves via EM.
October 6, 2003 at 3:17 pm
It seems kind of ass-backwards but you could create blank tables of the structure needed in the filegroup needed with a different name then DTS the data into them, rename the old tables and rename the new ones.
"I met Larry Niven at ConClave 27...AND I fixed his computer. How cool is that?"
(Memoirs of a geek)
"I met Larry Niven at ConClave 27...AND I fixed his computer. How cool is that?"
(Memoirs of a geek)
October 6, 2003 at 3:19 pm
It might also be interesting to see a profile trace of SQL Server moving a table from one filegroup to another.
I suppose a simpler method if you have the drive space would be to create a complete DDL of the database, alter the script with the new filegroup info, create the database and DTS all the data into it.
"I met Larry Niven at ConClave 27...AND I fixed his computer. How cool is that?"
(Memoirs of a geek)
"I met Larry Niven at ConClave 27...AND I fixed his computer. How cool is that?"
(Memoirs of a geek)
October 6, 2003 at 3:26 pm
quote:
Is there no other way?? I've got 170 tables and 108 indexes to move. Creating a dummy index and then dropping it will take just as long, if not longer, than doing the moves via EM.
Are you talking about your time or the server's time? If you mean the time it takes you to do this, that could be eased by just writing a script with a cursor. If you mean the time that the server takes to complete each "copy," that would probably be faster if you did it through QA.
Couple of points:
--Jonathan
Edited by - jonathan on 10/06/2003 3:27:10 PM
--Jonathan
October 7, 2003 at 9:54 am
Time wise...I'm referring to both. This system is 24x7 and downtime needs to be held to a absolute minimum. As for adding clustered indexes, I can suggest it, but cannot just implement them as it is a vendor application and any modifications to the database schema must come from the vendor.
October 7, 2003 at 10:42 am
quote:
Time wise...I'm referring to both. This system is 24x7 and downtime needs to be held to a absolute minimum. As for adding clustered indexes, I can suggest it, but cannot just implement them as it is a vendor application and any modifications to the database schema must come from the vendor.
If tempdb is on a different physical array, and has space for this, the index creation will not take as long if you use the WITH SORT_IN_TEMPDB option, particularly if the heaps have nonclustered indexes.
I cannot imagine that all tables must be moved together, so perhaps you could perform the operations on some of the smaller tables to gauge how long they are locked, and then develop the "downtime" strategy for the larger tables.
--Jonathan
--Jonathan
June 21, 2005 at 7:52 am
I wrote a script that reliably moves a table to another filegroup.
You can find it on
http://education.sqlfarms.com/ShowPost.aspx?PostID=59
-----------------------
Omri Bahat
SQL Farms Solutions
Editor's Note: : Dr. Omri Bahat works for SQLFarms, a software vendor of SQL Server tools.
January 25, 2008 at 4:52 am
With the greatest respect, as with most storage management, SQL Server is basic in comparison to Oracle:
ALTER TABLE TABLE_NAME MOVE TABLESPACE TABLESPACE_NAME
March 20, 2008 at 7:38 am
Omri,
Your link is broken.
All interested,
I profiled doing this through EM, it creates a new temp table in the new tablespace, populates it, drops the old table and then renames the new (temp) table to the name of the former.
I found this article (http://decipherinfosys.wordpress.com/2007/08/14/moving-tables-to-a-different-filegroup-in-sql-2005/) which outlines how to move the clustered indexes (and tables via code.)
Chris.
Chris.
October 9, 2008 at 1:46 pm
Omri script works great. I have used it a couple of time.
September 23, 2009 at 6:14 am
Which is faster when moving a table to new filegroup: (table wheighs 400GB)
-----------------------------------------------------
--[1]
sp_rename 'TAB1' , 'TAB1_OLD' -- located on OLD_FG
GO
CREATE TABLE TAB1
( [primaryKey] [int] IDENTITY(1,1) NOT NULL,
[description] [varchar](2000) NULL,
[id] [varchar](15) NULL,
[name] [varchar](500) NULL,
[length] [int] NULL,
[bulkData] [image] NULL,
[timestamp] [varchar](20) NULL)
ON [new_FG] TEXTIMAGE_ON [new_FG]
GO
INSERT INTO TAB1 ()
SELECT
FROM TAB1_OLD
GO
DROP TABLE TAB1_OLD
GO
CREATE CLUSTERED INDEX [CIX_TAB1_id] ON TAB1([id]) ON [new_FG]
GO
ALTER TABLE TAB1 ADD CONSTRAINT [PK_TAB1] PRIMARY KEY NONCLUSTERED ([primaryKey]) ON [new_FG]
GO
-----------------------------------------------------------------
or
-----------------------------------------------------------------
--[2]
DROP INDEX [CIX_TAB1_id]
GO
ALTER TABLE TAB1 DROP CONSTRAINT PK_TAB1 WITH (MOVE TO [new_FG])
GO
CREATE CLUSTERED INDEX [CIX_TAB1_id] ON TAB1([id]) ON [new_FG]
GO
ALTER TABLE TAB1 ADD CONSTRAINT [PK_TAB1] PRIMARY KEY NONCLUSTERED ([primaryKey]) ON [new_FG]
GO
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply