By default the database files will be restored to the directories from which they came
在计算机上 A 我创建了一个Bak文件
c:\ Program Files \ Microsoft SQL Server \ MSSQL.1 \ MSSQL \ Data \ aaa.mdf
我要去电脑 B (尝试恢复bak文件)(到 D驱动器,其中包含SQL文件夹)
并输入:(这些文件夹适用于计算机 B 的文件夹)。
RESTORE DATABASE aaa FROM DISK = '\\dsmain\OLD_DB\aaa.bak'
WITH REPLACE , MOVE 'aaa' TO 'D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\aaa.mdf',
MOVE 'aaa_log' TO 'D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\aaa_log.ldf'
ALTER DATABASE aaa SET MULTI_USER
结果:
http://i.stack.imgur.com/lD8u3.jpg
即使我去SMMS:
http://i.stack.imgur.com/pIpC7.jpg
我可以看到他搜索他的原始路径。
问题:
如何告诉他程序化,不恢复为原始位置但我的位置?
答案 0 :(得分:1)
--check contents of backup file
restore FILELISTONLY from
disk = 'c:\temp\mydatabase.bak'
--restore backup file
restore database mydatabase
from disk = 'c:\temp\mydatabase.bak'
with replace,
move 'mydatabase' to 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mydatabase.mdf',
move 'mydatabase_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mydatabase.ldf'