RESTORE DATABASE AdventureWorks2012 FROM DISK = 'D:\AdventureWorks2012.BAK'
GO
在上面的查询中,您需要记住.mdf/。LDF文件位置。
你可能会得到错误
C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL.1\MSSQL\DATA\AdventureWorks.MDF"failed with the operating system error 3(系统无法找到指定的路径)。(Microsoft.SqlServer.SmoExtended)
因此,您需要运行Query,如下所示
RESTORE FILELISTONLY
FROM DISK = 'D:\AdventureWorks2012.BAK'
一旦你运行上面的查询,你会得到mdf/ldf的位置使用它恢复数据库使用查询
USE MASTER
GO
RESTORE DATABASE DBASE
FROM DISK = 'D:\AdventureWorks2012.BAK'
WITH
MOVE 'DBASE' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.DBASE\MSSQL\DATA\DBASE.MDF',
MOVE 'DBASE_LOG' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.DBASE\MSSQL\DATA\DBASE_1.LDF',
NOUNLOAD, REPLACE, NOUNLOAD, STATS = 5
GO