Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Question about restore database and create new fil

Author  Topic 

lee.jenkins
Starting Member

5 Posts

Posted - 2009-04-29 : 01:13:59
Recently, I am moving a database from one server to another server due
to the storage issue. The existing database is about 30G, all tables
are in one filegroup and one primary data file.

I want to create separated filegroups and data files to re-organize
the whole database. My question is what is the best way to do that?

One way I can restore the database still to one filegroup and one data
file, then I add filegroups and data files to the restored database,
then alter tables to move to different filegroups. (I have a side
question about this too, I know I can Alter table to drop indexes with
Move to option, and then recreate indexes to move tables to other
filegroup, but I do have one table don't have any primary key, don't
have any index on it, how could I move that table then?)

I am thinking about is that possible I can create database with
filegroups and data files first and then restore the database, during
the restore process, can I specify the filegroups each table should
use?

Or if there is any better way to do that?

Thanks a lot!

ahmad.osama
Posting Yak Master

183 Posts

Posted - 2009-04-29 : 06:12:04
quote:
Originally posted by lee.jenkins

Recently, I am moving a database from one server to another server due
to the storage issue. The existing database is about 30G, all tables
are in one filegroup and one primary data file.

I want to create separated filegroups and data files to re-organize
the whole database. My question is what is the best way to do that?

One way I can restore the database still to one filegroup and one data
file, then I add filegroups and data files to the restored database,
then alter tables to move to different filegroups. (I have a side
question about this too, I know I can Alter table to drop indexes with
Move to option, and then recreate indexes to move tables to other
filegroup, but I do have one table don't have any primary key, don't
have any index on it, how could I move that table then?)

I am thinking about is that possible I can create database with
filegroups and data files first and then restore the database, during
the restore process, can I specify the filegroups each table should
use?

Or if there is any better way to do that?

Thanks a lot!



you can use copy database option in SSMS to move the database If the servers are in a network.

As per my knowledge u can't specify file groups for tables during restore.

After restoring add secondary file group and move the tables either thru SSIS or by altering index.






Regards,
Ahmad Osama
Go to Top of Page

lee.jenkins
Starting Member

5 Posts

Posted - 2009-04-29 : 15:57:36
Thanks a lot for the help.

I did a little bit research, but did not find any useful guide on how to move table to other filegroup in SSIS, could you please give me some sample if you have.

Also for the altering method, I am not sure if there is no index and primary key at all for some tables, can I still use alter statement to move table?

Thanks for the help.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-04-29 : 18:26:33
NO. you need to have clustered index created in table so that you can move it to other Filegroup. Create clustered index and move it. Spreading data files accross FG will be useful when separating accross multiple disks.
Go to Top of Page

lee.jenkins
Starting Member

5 Posts

Posted - 2009-04-29 : 18:53:47
quote:
Originally posted by sodeep

NO. you need to have clustered index created in table so that you can move it to other Filegroup. Create clustered index and move it. Spreading data files accross FG will be useful when separating accross multiple disks.



Thanks, so I have to create clustered index for those tables which don't have it to move those tables to new FG, then remove the index. It will take a while to generate indexes for those tables.

Another question, for non-clustered indexes, is it better to put them on separated logic drives other than the logic drive cluster index and table itself on?

Thanks a lot!
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-04-29 : 21:43:43
Depending on number of PHYSICAL drive ,you can partition your index data,data files,Tempdb files and log files ,backup files in separate drives to maximize performance.
Go to Top of Page

ahmad.osama
Posting Yak Master

183 Posts

Posted - 2009-04-30 : 01:44:45
quote:
Originally posted by sodeep

Depending on number of PHYSICAL drive ,you can partition your index data,data files,Tempdb files and log files ,backup files in separate drives to maximize performance.



I wud rather say that depending on your database size u shud arrange for storage devices and place files as desired...

Regards,
Ahmad Osama
Go to Top of Page

ahmad.osama
Posting Yak Master

183 Posts

Posted - 2009-04-30 : 01:51:19
quote:
Originally posted by lee.jenkins

quote:
Originally posted by sodeep

NO. you need to have clustered index created in table so that you can move it to other Filegroup. Create clustered index and move it. Spreading data files accross FG will be useful when separating accross multiple disks.



Thanks, so I have to create clustered index for those tables which don't have it to move those tables to new FG, then remove the index. It will take a while to generate indexes for those tables.

Another question, for non-clustered indexes, is it better to put them on separated logic drives other than the logic drive cluster index and table itself on?

Thanks a lot!



for table with out clustered index.....let's say that u have a table
tbl_Customers and u want to change the file group

1) Create a temp table #temptbl_Customers
2) insert data into #temptbl_Customers from #tbl_Customers
3) Drop and Create table tbl_customers with On 'Filegroup' option specifying the file group u want to transfer to OR
make the secondary filegroup the default filegroup
4) insert the data into #tbl_Customers from #temptbl_Customers

u can wrap this up in an SSIS package....
also in for each loop container u can select the tables with out clustered index and pass them to the procedure

In this way u will have ur task fully automated







Regards,
Ahmad Osama
Go to Top of Page

lee.jenkins
Starting Member

5 Posts

Posted - 2009-04-30 : 15:04:40
Thanks guys, it really help me a lot.
Go to Top of Page
   

- Advertisement -