use test
go
alter proc restore_mdf_ldf_main (@database varchar(100), @mdf varchar(100),@ldf varchar(100),@filename varchar(200))
as
begin
begin try
RESTORE DATABASE @database FROM DISK = @FileName
with norecovery,
MOVE @mdf TO 'D:\sql samples\sample.mdf',
MOVE @ldf TO 'D:\sql samples\sample.ldf'
end try
begin catch
SELECT ERROR_MESSAGE() AS ErrorMessage;
print 'Restoring of the database ' + @database + ' failed';
end catch
end
exec restore_mdf_ldf_main product,product,product_log,'c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\product.bak'
是的,當您有兩個文件時,您可以[附加數據庫](http://technet.microsoft.com/en-us/library/ms190209.aspx)。 –
我試圖這樣做,但它會在連接數據庫時發生錯誤。 –
錯誤說無法打開物理文件。 操作系統錯誤5(訪問被拒絕) MSSQL服務器錯誤5120 –