itpartner_danmark
asked on
SQL server move table to another file in filegroup
Have created a new filegroup for a database and want to move a table called "Pictures" from the primary filegroup to the new "Pictures" filegroup.
Dont know how to move the specific table to the new filegroup. I have done some googling and can see that I have to move the Index.
In SQL Server Management Studio I navigate to server / Databases / Mydatabase/ Tables/ Pictures / Indexes:
I see the following three indexes:
IxTblPictures (Non-Unique, Non-Clustered)
IxTblPictures1 (Non-Unique, Non-Clustered)
PkTblPictures (Clustered)
If I right click/properties on the clustered index and select Storage in the left pane, then the right pane is grayed out, so I cannot choose the new filegroup. WHY???
On the Non-Unique, Non-Clustered indexes I can change settings in the right pane under Storage.
I have never tried this before. Am I on the right track or is there a better way of moving a table to another file group.
Dont know how to move the specific table to the new filegroup. I have done some googling and can see that I have to move the Index.
In SQL Server Management Studio I navigate to server / Databases / Mydatabase/ Tables/ Pictures / Indexes:
I see the following three indexes:
IxTblPictures (Non-Unique, Non-Clustered)
IxTblPictures1 (Non-Unique, Non-Clustered)
PkTblPictures (Clustered)
If I right click/properties on the clustered index and select Storage in the left pane, then the right pane is grayed out, so I cannot choose the new filegroup. WHY???
On the Non-Unique, Non-Clustered indexes I can change settings in the right pane under Storage.
I have never tried this before. Am I on the right track or is there a better way of moving a table to another file group.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This one tells me that the Pictures filegroup is almost empty. It says 6 GB free space in the Pictures filegroup and that is the initial size.
SELECT file_id, name, physical_name,
'Free Space (MB)' =
(size - FILEPROPERTY(name,'SpaceUs ed'))/128. 00
FROM sys.database_files
So Im wondering if I did something wrong?
SELECT file_id, name, physical_name,
'Free Space (MB)' =
(size - FILEPROPERTY(name,'SpaceUs
FROM sys.database_files
So Im wondering if I did something wrong?
ASKER
It seems that the table pictures now is on the filegroup called Pictures:
But when I check for free space it seems that no data has been moved since there is allmost 6 gb free space in the filegroup Pictures (GalArtoPics) and that is the initial size of the file.
When will the data be moved. Do I have to take the Database offline and online again, and how long will it take for the DB to come online again?
But when I check for free space it seems that no data has been moved since there is allmost 6 gb free space in the filegroup Pictures (GalArtoPics) and that is the initial size of the file.
When will the data be moved. Do I have to take the Database offline and online again, and how long will it take for the DB to come online again?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
PICTURES is the Filegroup 2 in the filestats output.
I got no errors when running the CREATE INDEX commands, and it also seems that the TblPictures is stored on the PICTURES filegroup.
But its strange that the data doesnt move. This table stores a lot of highres images.
I got no errors when running the CREATE INDEX commands, and it also seems that the TblPictures is stored on the PICTURES filegroup.
But its strange that the data doesnt move. This table stores a lot of highres images.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I dont know what you mean / sorry.
So the text filegroup has nothing to do with my problem with data not moving?
So the text filegroup has nothing to do with my problem with data not moving?
ASKER
ASKER
SOLVED: It took 12 minutes to apply the change.
Thanks for pointing this out. I never use the GUI to make table structure changes, so I was not aware of this.
I didn't see anything in the normal SQL commands to make this change. My guess is that the GUI is writing a script that: copies the table data out, (re)creates the table, and copies the data back in.
I didn't see anything in the normal SQL commands to make this change. My guess is that the GUI is writing a script that: copies the table data out, (re)creates the table, and copies the data back in.
ASKER
CREATE UNIQUE CLUSTERED INDEX [PkTblPictures] ON [dbo].[tblPictures]
(
[PictureID] ASC
) WITH (DROP_EXISTING = ON)
ON [Pictures]
GO
CREATE NONCLUSTERED INDEX [IxTblPictures] ON [dbo].[TblPictures]
(
[WorkID],[PictureID] ASC
) WITH (DROP_EXISTING = ON)
ON [Pictures]
GO
CREATE NONCLUSTERED INDEX [IxTblPictures1] ON [dbo].[TblPictures]
(
[PictureID],[WorkId] ASC
) WITH (DROP_EXISTING = ON)
ON [Pictures]
GO