Restore Database in Sql Server From .bak or .mdf File Using Query

In this tutorial i will explain how to restore database in sql server from .bak or .mdf file using query. or how to write query to restore database backup files (.bak or .mdf) in sql server. To restore database backup in sql server we need to write query like “RESTORE DATABASE DatabaseName FROM Disk…etc”.
Generally, to restore database in sql server we have different kind of methods you can also restore database backup by using sql server management studio.

1). Using Sql Query statement.
2). Using from sql server management studio

So, To restore database by using sql server query we need to write the query like as shown below

First we will see the syntax of the Query to restore database
RESTORE DATABASE YourDatabaseName
FROM DISK = 'Your .bak file Path'
WITH
MOVE 'mdffilename' TO 'Your .mdf file path',
MOVE 'ldbfilename' TO 'Your .ldf file path'
, REPLACE
Now, Let's Write actual Query to Restore .mdf file from .bak file.
RESTORE DATABASE ProjectMania
FROM DISK = 'E:\DB\ProjectMania.bak'
WITH
MOVE 'ProjectMania' TO 'E:\DB\ProjectMania.mdf',
MOVE 'ProjectMania_log' TO 'E:\DB\ProjectMania.ldf'
, REPLACE
Output/Demo:


Now, refresh your databases and check for your restored database.
Previous
Next Post »

If you have any kind of question about any post, Feel free to ask.You can simply drop a comment below post. Your feedback and suggestions will be highly appreciated. ConversionConversion EmoticonEmoticon