我需要恢复具有多个文件组的分区数据库。在SSME的还原选项中,我需要手动编辑文件组还原的所有路径作为选项,因为它有超过150个文件组,所以有点单调乏味
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
这里我需要为所有文件组指定多个MOVE命令,当拥有100个文件组时,这是一项繁琐的任务
MOVE 'MyNwind_data_1' TO 'D:\MyData\MyNwind_data_1.mdf',
MOVE 'MyNwind_data_2' TO 'D:\MyData\MyNwind_data_2.ndf'
我需要将文件移动到我作为参数提供的路径中。
答案 0 :(得分:1)
您可以使用以下查询生成MOVE列表:
select 'MOVE ''' + name + ''' TO ''D:\MyData\' + name + '.mdf'','
from sys.filegroups
答案 1 :(得分:1)