USA: +1 888 900 4529     UK: +44 800 088 5522


How to Restore SQL Server Database From MDF File in Every Possible Case

Tej Pratap Shukla | Modified: 2019-04-06T06:13:19+00:00 | SQL Server, Tips|
restore database from MDF file in SQL Server

The answer of most awaited query – How to restore SQL Server database from MDF file? Will describe in this article. So, keep an eye on this post and get the most appropriate solutions. Let’s begin!

In Microsoft SQL Server, the table database saves in primary storage file i.e., MDF or Master Database File. However, there are multiple scenarios where the user requires to restore database from primary MDF filein SQL Server. Some common ones are described here;

  • Switching from current Microsoft SQL Server to a higher edition.
  • Need to import orphaned MDF File data in MS SQL Server
  • Requirement to restore database from corrupt SQL MDF File

In fact, there are some other reasons also that require attachment of MDF to the SQL Server to view its table. So, after considering this query, we came up with this post. Here, readers will know all the methods that use to recover SQL Server database from healthy or corrupted MDF file.

How to Restore Database From MDF File in SQL Server 2017 / 2016 / 2014

In the following section, we consider two situations where user face difficulty to restore SQL database from the MDF.

  • SQL Server Import Database from Healthy MDF File
  • Recover Data from Corrupted MDF File

Situation 1: Restore Database From Non-Corrupted SQL MDF File

Basically, there are two ways through which user can achieve the same. Although, the MDF file should be corruption free.

#Approach 1: Using SQL Management Studio

You need to follow the following instructions and restore the MDF file database.

    1. First of all, you need to start the Microsoft SQL Server Management Studio.
    2. Once it is opened, go to Object Explorer section.
    3. After that, you need to right-click on Database and opt for Attach from the menu.

SQL Server Database Option

    1. An Attach Databases wizard open, click on Add button as shown in the screenshot.

Upload MDF File

    1. Now, browse the MDF file whose database you want to restore and click on OK.

Opt MDF for SQL Recovery

    1. Here, you can clearly view the MDF and LDF file under the database details section. Afterward, click on OK to restore the database in SQL Server.

View Selected MDF & LDF FIle

  1. Refresh the database and you will see the database of MDF file that you just attached.

#Approach 2: Take the Help of T-SQL

A user can also opt another way to restore SQL Server database from MDF file via. T-SQL. In this workaround, you need to execute the following script in the management studio.

ON (FILENAME = ‘C:\FilePath\File_name.mdf’)

Recover MS SQL Server database

After executing this command successfully, refresh the database and you will see the newly restored database under the Object Explorer.

Situation 2: Restore SQL Server Database From Corrupted MDF File

In such a situation when the SQL primary database is corrupted, then above-mentioned workaround does not work. For this, you need to repair the corrupted MDF file and then attach the healthy file with SQL Server. This can be done by SysTools SQL MDF File Recovery Software.It is an intelligent automated utility that fixes the corrupted SQL Server Primary & Secondary database file.

No matter how corrupt your MDF & NDF file is, the tool repairs it efficiently in a minimum span of time. Its prime function is to deeply scan database file and restores Tables, Views, Stored Procedure, Functions, Rules, and Triggers. One can directly export the recovered MDF file into Live SQL Server environment and as SQL Scripts.

What’s More – In fact, you can transfer only schema or complete schema along with data from MDF file on designated location. Plus, you are free to export selective data from MDF file instead of the entire database. One can repair MDF & NDF file of any SQL Server, including SQL Server 2017 / 2016 / 2014 / 2012 / 2008 / 2008 R2 / 2005 / 2000.

Let’s check out how the tool restore database from corrupt MDF file.

    1. Install the Software and click on Open to load MDF file.
    2. An Add File wizard opens, just opt for Scan Mode and select version of MDF File.In case, if you do not know the version, then check the box labeled as Auto detect SQL server (.mdf) version.

Load MDF File

    1. After file scanning, click on Export.

 Export Option

    1. On Export window, select all the advanced settings as per your requirement and click on Export.

Recover corrupt primary file

    1. A live real-time export report will display on the screen where user can analyze the on-going process.

View Live Status

Finally! Get the Database

As we said above, there are lots of reasons where a user need to attach the SQL Server with MDF file to access its database. However, due to lack of knowledge about the right methods, user becomes unable to do the same. Therefore, we have described a complete tutorial on how to restore SQL Server database from MDF File. This guide works for healthy as well as corrupted SQL Server MDF.

Leave a Reply

Your email address will not be published.

Exclusive Offers & Deals, Grab it Now!

Systool Offer