Home » SQL » Simplest way to restore MSSQL Server database

Simplest way to restore MSSQL Server database

Here’s a simplest way I found (so far) to restore a database in MS SQL Server. First part lists “logicalnames” from the backup that you want to restore. Modify the path so it points to the actual path where your backup file is:

RESTORE FILELISTONLY FROM DISK = N'C:\[path]\[db_name_backup].bak'
 GO

This shows LogicalName and PhysicalName of the data and log backup files, which have to be used in the following script:

RESTORE DATABASE [db_name]
 FROM DISK = N'C:\[path]\[db_name_backup].bak'
 WITH FILE = 1,
 MOVE N'[data_file_logical_name]' TO N'C:\[restored_db_path]\[data_file_name].mdf',
 MOVE N'[log_file_logical_name]' TO N'C:\[restored_db_path]\[log_file_name].ldf',
 NOUNLOAD,
 STATS = 10
 GO

That’s it. Pretty simple, isn’t it?

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>