The solution is applicable to various versions of MS SQL Server, including 2016, 2014, 2012, 2008, 2008 R2, and 2005.
The master database file (MDF) is the primary user database file that holds the main configuration details and all major data of SQL Server. If the server experiences a sudden shutdown, crash, or is affected by a virus, the MDF file can become corrupted or damaged. In such cases, restoring the MDF file is the most effective approach to resolve the issue.
Restoring the master database in SQL Server 2008 or 2012 can be achieved in two ways. Either you can restore the master database from a backup file, or you can restore the MDF file without a backup. Depending on your situation, you can choose one of these two methods to resolve the issue.
If you have a backup of the SQL server master database, you can easily restore the MDF file by following a few simple steps. Simply copy the backup file to the server, open SQL Server Management Studio, right-click on the server name in the Object Explorer, and select "Tasks" > "Restore" from the context menu.
RESTORE DATABASE master FROM WITH REPLAC
The "replace" command in the restoration process continues even if there is a database with the same name, and the existing database will be removed.
After the master database restoration is complete, the SQL Server instance will shut down. To proceed, remove the single-user startup parameter and set the server to multi-user mode before restarting it.
SQL Server (MSSQLSERVER)
SQL Server Agent (MSSQLSERVER)
SQL Server Reporting Services (MSSQLSERVER)
If you're new to SQL Server or haven't created a backup, you can still restore the master database using the Qiling MS SQL Recovery tool. This professional software can recover MDF files and their components, including tables, triggers, indexes, keys, rules, and stored procedures, as well as deleted records from the SQL database.
Step 1. Stop MS SQL Server service via services.msc or Management Studio.
Step 2. Run Qiling SQL Recovery, select the MDF/NDF file of the database you want to restore, and click "Repair" to start repairing your MDF/NDF file in the main interface.
If you know the exact location of the file, click "Browse" to locate the database. This will allow you to select the file from your computer and upload it to the system.
If you're unsure about the location of the file, click on the "Search" button to search for the .mdf or .ndf file in your system.
Step 3. After the recovery process is complete, the recovered database objects will be listed in the left pane of the window, allowing you to see the results of the operation.
Step 4. To export your database objects, click the "Export" button located in the bottom right corner of the screen. This will allow you to save your database objects in a preferred format, such as MDF (Microsoft Database File) or SQL scripts.
On the "Export to database" window, choose "Create new database" to create a new database and enter the database name and SQL location, or select "Export to existing database" to export to an existing database, selecting the database from the list.
Step 5. Now restart the SQL Server.