Introduction
In this tip, I would like to show you how to rebuild the master/system database in SQL Server 2008 R2. Recently, I faced a problem related to the master database. My instance was unable to start due to master file corruption.
Case Study
Recently, one of my instances was corrupted and I was unable to restart SQL Server. I did the following steps to get it back. First I checked the SQL Server ERRORLOG. Please go through the following steps.
Step 1: Check the error log where it is showing master was corrupted.
Step 2: Rebuild system databases from command prompt. Go to the following path and run setup as follows:
C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\SQLServer2008R2
Step 3: Once the above command runs successfully, check in the summary.txt file as follows and look at the Requested action.
Step 4: Start SQL Server service.
Step 5: Connect to the instance. But you cannot see any user defined databases. The rebuilding process has created a fresh master database so there are no other databases and all previous configuration values are lost.
Step 6: Now we can restore the master database to get the previous configuration settings. Go to command prompt and run server in single user mode as follows:
Step 7: Connect to the instance and take new query to restore master database. Once we restore master database, then we can get all the previous configuration values including user defined databases.
Step 8: Click on Connect button and connect to the instance as follows:
Step 9: Restore master database as follows
Step 10: Restart SQL Server instance in multi user mode and connect to SQL Server Management Studio. We can see all user databases as follows:
Troubleshooting
Sometimes, the rebuild process may fail if there is problem with files present in Binn\Templates folder. Once you check summary.txt file, let's say it is saying one message as follows:
Configuration error description: The file C:\Program Files\Microsoft SQL Server \
MSSQL10_50.MSSQLSERVER \MSSQL\Binn\Templates\master.mdf is missing
In the above scenario, we have to copy file (master.mdf) from SQL Server dump or DVD into Binn\Templates folder and retry.
Summary
We can summarize the key points as follows according to BOL regarding rebuilding system databases:
- SQL Server 2000
- We can use RebuildM.exe
- Need setup media for system database files
- SQL Server 2005
- We can use setup.exe
- Need setup media for setup.exe and system database files
- SQL Server 2008
- We can use setup.exe
- Setup media not required and system database files are there in Binn\Templates folder
Happy learning!