Works with MS SQL Server 2016, 2014, 2012, 2008, 2008 R2, and 2005

The primary database file, i.e. the .MDF file, is the principal user database file of SQL Server that stores all crucial configuration details and main data. In case the SQL Server gets corrupted due to an unexpected shutdown, crash, or virus attack, the primary database file gets affected. In such a scenario, recovering MDF files is the ultimate solution to fix the issue.

How to Restore Master Database in SQL Server

How to Restore a SQL Server Master Database with or without a Backup

When you need to restore the master database in SQL Server 2008 or 2012, there are usually two solutions. One is to restore the SQL Server master database from a backup file, and the other is to restore the MDF file without using a backup. Depending on your situation, choose one of these two different methods to solve the problem.

Solution 1: Restore the Master Database in SQL Server from a Backup File

If you have a backup of the master database for your SQL Server, restoring an MDF file is not complicated.

Note:
If you haven't created any backup of your SQL Server database, skip this method and go to Solution 2 to restore the primary SQL Server database without a backup file.

Step 1: Set your SQL Server instance to single-user mode.

    • Log on as an administrator to the SQL server > Go to Administrative Tools > Services, right-click the SQL Server (MSSQLSERVER) service, and click Stop.
    • Double-click SQL Server (MSSQLSERVER) to open the Service Properties window.
    • Click the General tab, and in the Startup parameters field, type -c -m.
    • Click Start on the General tab to set the server to single-user mode, and then click OK to close the dialog box.

How to Recover SQL Server Master Database

Step 2: Run the Transact-SQL command to restore the master database on the SQL Server.

RESTORE DATABASE Master FROM DISK = 'D:\Backup\Database.bak' WITH REPLACE

The “replace” instruction indicates that if a database with the same name already exists, the restore process should continue and the existing database should be removed.

Step 3: Set Microsoft SQL Server to multi-user mode.

When the master database restore is complete, the SQL Server instance will shut down. Before restarting the server, you must remove the single-user startup parameter and set Microsoft SQL Server to multi-user mode.

    • Log on to the SQL Server as an administrator.
    • Go to Administrative Tools > Services, right-click the following services, and then click Start:

SQL Server (MSSQLSERVER)

SQL Server Agent (MSSQLSERVER)

SQL Server Reporting Services (MSSQLSERVER)

Step 4. Restart the SQL Server instance and perform any additional recovery tasks as needed.

Solution 2: Recover SQL Server Master Database Without Backup File

If you are new to SQL Server, have insufficient knowledge of SQL databases, or have never created a backup before, you can also use professional MS SQL Recovery tool to restore the master database in SQL Server. It can recover MDF files along with their components (tables, triggers, indexes, keys, rules, and stored procedures), as well as records deleted from an SQL database.

Step 1. Stop the MS SQL Server service using either services.msc or Management Studio.

Step 2: Run the SQL Recovery tool. On the main interface, select the MDF/NDF file of the database that you want to recover. Click on 'Repair' to start the repairing process of your MDF/NDF files.

If you know where the file is located, click Browse to locate the database.

If you do not know the location of the file, click Search to search for the .mdf or .ndf file.

How to Restore Database from MDF File in SQL Server - Step 2 How to Restore Database from MDF File in SQL Server - Step 2

When finished, you will see the recovered database objects in the left pane of the window.

How to Restore Database from MDF File in SQL Server - Step 3

Click “Export” in the bottom right corner of the screen to save the database objects. Choose the desired format, such as MDF or SQL script.

In the Export to Database window, choose Create New Database or Export to Existing Database to save the recovered data. If you select Create New Database, enter the database name and choose the SQL location. If you select Export to Existing Database, select an existing database.

How to Recover Database from MDF File in SQL Server - Step 4 How to Recover Database from MDF File in SQL Server - Step 4

Step 5 Restart SQL Server.