tags:

views:

41

answers:

2

does anyone have any query to restore partioned db that having multiple file groups,In the restore option in the SSME i need to edit manually all the path of the filegroups restore as option it little bit tedious as it having more than 150 filegroups

eg:USE master
GO
-- First determine the number and names of the files in the backup.
RESTORE FILELISTONLY
   FROM MyNwind_1
-- Restore the files for MyNwind.
RESTORE DATABASE MyNwind
   FROM MyNwind_1
   WITH NORECOVERY,


      MOVE 'MyNwind_data_1' TO 'D:\MyData\MyNwind_data_1.mdf', 
       MOVE 'MyNwind_data_2' TO 'D:\MyData\MyNwind_data_2.ndf'

GO
-- Apply the first transaction log backup.
RESTORE LOG MyNwind
   FROM MyNwind_log1
   WITH NORECOVERY
GO
-- Apply the last transaction log backup.
RESTORE LOG MyNwind
   FROM MyNwind_log2
   WITH RECOVERY
GO

Here i need to specify multiple MOVE command for all my filegroups,this is a tedious task when having more than 100s of filegroups

   MOVE 'MyNwind_data_1' TO 'D:\MyData\MyNwind_data_1.mdf', 
           MOVE 'MyNwind_data_2' TO 'D:\MyData\MyNwind_data_2.ndf'

I need to move the files into the path i provided as a parameter.Please help.

Regards Renju http://blog.renjucool.com

A: 

You could generate the MOVE list with a query like:

select 'MOVE ''' + name + ''' TO ''D:\MyData\' + name + '.mdf'','
from sys.filegroups
Andomar
A: 

Please find these queries http://code.msdn.microsoft.com/Sql2008PartionedDb/

renjucool