Step 1
RESTORE FILELISTONLY FROM DISK='D:\A.bak'
此时结果集会显示A备份数据库的数据文件和日志文件的逻辑名称,后面的步骤需要用到上述查询的数据库逻辑名
Step 2:
RESTORE DATABASE B FROM DISK='D:\A.bak'
WITH
MOVE 'A' TO 'D:\B.mdf',
MOVE 'A_log' TO 'D:\B_log.ldf'
其中‘A’ 和'A_log'替换为Step1查询的逻辑名
declare @DB_FILE varchar(256);
SET @DB_FILE= 'F:\Test2202212071447\Test2202212071447.bak' ;
RESTORE HEADERONLY FROM DISK = @DB_FILE
GO
RESTORE FILELISTONLY FROM DISK=@DB_FILE
RESTORE DATABASE Test2 FROM DISK = @DB_FILE
WITH MOVE 'Test _data.mdf' TO 'G:\DB\TaiG.mdf',
MOVE 'Test _log.ldf' TO 'G:\DB\TaiG_log.ldf',
MOVE 'Test _FileStream' TO 'G:\DB\TaiG_FileStream'
GO
网友评论