Restore Database .bak (.mdf) File using Query or Management Studio in SQL Server

Introduction:
This article explains how to write restore database in sql server from .bak or .mdf file using query or restore database backup using sql server management studio. To restore database backup in sql server we need to write query like “RESTORE DATABASE DatabaseName FROM Disk…etc” or directly from management studio we can restore database in sql server.

 To restore database in sql server we have different methods
       1.    with Query
       2.    Directly from sql server management studio


 Restore database
with Query:

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

-------------------------------------------------------------------------------------------------------------------
 RESTORE DATABASE yourdbname
FROM DISK = 'E:\yourbackfile.bak'
WITH
MOVE 'mdffilename' TO 'E:\datayourmdffilename.mdf',
MOVE 'ldbfilename' TO 'E:\datayourldffilename.ldf'
, REPLACE
----------------------------------------------------------------------------- 

Example:
--------------------------------------------------------------------------------------------------------------------
RESTORE DATABASE MySampledb
FROM DISK = 'E:\mysampledb.bak'
WITH
MOVE 'MySampledb' TO 'E:\MySampledb.mdf',
MOVE 'MySampledb_log' TO 'E:\MySampledb.ldf'
, REPLACE
-------------------------------------------------------------------------------------------------------------------- 

Now refresh your databases and check for your restored database

With SQL Server Management Studio

To take database backup directly from sql server management studio we need to follow below steps

Open sql server management studio à Select your database à Right click on it and select Tasks in that select Backup and click on it like as shown below



 Whenever we click on Restore Database option it will open new window in that give database name and select from device option in source to restore section like as shown below 


Now click on upload icon in from device option to give database backup file path. Whenever we click on upload icon we will get another window to specify database like as shown below 



Now click Add option to specify database backup file (.bak or .mdf format) path and click OK once we add our database backup file path that will be like as shown below  





Now click OK it will added in restore database section in that select Restore option and click OK to restore database that would be like as following screen



Once everything done we will get success message like as shown below


Ashwani
Ashwani

This is a short biography of the post author. Maecenas nec odio et ante tincidunt tempus donec vitae sapien ut libero venenatis faucibus nullam quis ante maecenas nec odio et ante tincidunt tempus donec.

No comments:

Post a Comment