Restore BackUp Script.
--Restore filelistonly gives infromation of .mdf andl .ldf logical filesnames.
RESTORE FILELISTONLY FROM DISK = 'D:\DatabaseName.BAK'
GO
RESTORE DATABASE DatabaseName FROM DISK = 'D:\DatabaseName.BAK'
WITH MOVE 'Database_Data' TO 'C:\DatabaseName_Data.mdf',
MOVE 'DatabaseName_Log' TO 'E:\DatabaseName_Log.ldf'
Some times we may get this while running the above script
Msg 3183, Level 16, State 2, Line 1
RESTORE detected an error on page (0:0) in database "DatabaseName" as read from the backup set.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
The reason for this is database is not completely backed up.For that we have to check the status of .BAK File .So First run these commands.
RESTORE HEADERONLY FROM DISK = 'GivePathHere\Name.BAK'
RESTORE FILELISTONLY FROM DISK = 'GivePathHere\Name.BAK'
The below query will tell us who is restoring database, when the database restoration process is in progress.
select s.original_login_name from sys.dm_exec_requests as r join sys.dm_exec_sessions as s on r.session_id = s.session_id where r.command = 'RESTORE'
Comments