Search This Blog

Tuesday, June 3, 2014

Restore backup in SQL Server using SQL Scripts


1) Place the backup file <SampleBackupFile.bak> to an accessible location <E:\SampleFolder>.



2) Retrieve the mdf and ldf file names of the database from the backup file using the below query.


RESTORE FILELISTONLY

FROM DISK = 'E:\SampleFolder\SampleBackupFile.bak'


3) Now restore the database <SampleDB> using the below query.


RESTORE DATABASE <SampleDB>

FROM DISK = 'E:\SampleFolder\SampleBackupFile.bak'
WITH MOVE 'mdf_filename' 
        TO 'E:\SampleFolder\SampleMDFFile.mdf',
     MOVE 'ldf_filename' 
        TO 'E:\SampleFolder\SampleLDFFile.ldf'

2 comments: