Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

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

Jul 30, 2015
Introduction:

Here I will explain 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.

Description:   
                        
In previous articles I explained take database backup in sql server, SQL injection attacks with example, SQL Server interview question and answers, joins in sql server, function example in sql server 2008, Primary key constraint in sql server, foreign key constraint in sql server, cursor example in sql server and many articles relating to SQL server. Now I will explain how to write query to restore database backup files (.bak or .mdf) in sql server management studio 2008.

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

With Query to Restore database:

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

Syntax of Query to restore database


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

Once we run above query we will get output like as shown below 


Now refresh your databases and check for your restored database

Directly from 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


I hope it helps you to restore your database……

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

8 comments :

Mahaveer Prajapati said...

very helpful, sir please tell me how u create some articles demo as in gif format?

girijesh.kumar said...

Thanks

girijesh.kumar said...

Plz share an articles about purge and shrink activity

girijesh.kumar said...

Plz share an articles about purge and shrink activity

Pushpam Abhishek said...

vry useful article

Santhakumar Munuswamy said...

Good Article. Thanks for sharing to us

hardeek mistry said...

I have one abc.bak file which i have to restore in Asp.net C# internal database (microsoft sql server) .what will be procedure ??

Unknown said...

same operation can you explain how to do via asp.net web application

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.