In Microsoft SQL Server, how can the master database be rebuilt in case it becomes corrupted, in a typical recommended approach?

Difficulty: Hard

Correct Answer: To rebuild the master database in SQL Server you run the SQL Server setup program with the rebuild database option (or equivalent command-line switch) to recreate the system databases, and then restore master from a known good backup and reapply necessary configurations.

Explanation:


Introduction / Context:
The master database in Microsoft SQL Server holds critical system information, including metadata about databases, logins, configuration settings, and more. If the master database becomes corrupted and you cannot start SQL Server normally, you may need to rebuild it. This is an advanced administration task. Interview questions about rebuilding master test whether candidates understand the proper, supported procedures rather than attempting dangerous ad hoc methods that could further damage the system.


Given Data / Assumptions:
• The platform is Microsoft SQL Server. • The master database is assumed to be damaged to the point that normal startup is affected. • The goal is to rebuild master in a supported, safe way. • We assume that a recent backup of master exists, although the rebuild step itself does not require it.


Concept / Approach:
Rebuilding the master database is not done by dropping it or manually deleting files. Instead, SQL Server provides a supported method using the setup program with parameters that rebuild the system databases (master, model, msdb, and tempdb) to their original state. After rebuilding, you typically restore master from a known good backup or reapply configuration scripts to recreate logins, linked servers, and other settings. This approach minimizes the risk of inconsistent metadata and follows Microsoft guidelines. The correct answer must mention running setup with the rebuild database option and restoring from backup or reconfiguring afterwards.


Step-by-Step Solution:
Step 1: Recognize that master is a system database and cannot be dropped or recreated with normal CREATE DATABASE commands. Step 2: Recall that SQL Server setup has a rebuild database option or command-line switch that can recreate the system databases to a clean state. Step 3: Understand that after rebuilding, you will need to restore master from a recent backup if available or manually reconfigure server level objects. Step 4: Note that ad hoc methods such as deleting files or shrinking to zero are unsupported and could make recovery harder. Step 5: Choose the option that describes running setup with rebuild database and then restoring master or reapplying configuration.


Verification / Alternative check:
Imagine a scenario where the master database is corrupted and SQL Server fails to start. Documentation and best practices instruct you to start setup with command-line arguments that include action for rebuilding databases. This process recreates system databases from template files installed with SQL Server. Once the service can start again, you restore the master database backup to recover your configuration, or if no backup exists, you manually recreate logins, jobs, and other objects. This method is controlled and repeatable. None of the alternative approaches, such as DROP DATABASE master or deleting files manually, are supported or safe, confirming that option a is correct.


Why Other Options Are Wrong:
Option b suggests dropping master with DROP DATABASE master, which is not allowed and would break the server. Option c proposes deleting master database files from the file system and restarting, which is unsupported and likely to prevent SQL Server from starting at all. Option d claims that shrinking master to zero size and then expanding it will rebuild it, which is not how SQL Server manages system databases. Option e implies running DBCC CHECKDB on a user database will automatically rebuild master, which is not true; DBCC CHECKDB is used for consistency checking and repair of individual databases, not for rebuilding system databases.


Common Pitfalls:
A major pitfall is attempting unsupported manual fixes on the master database, such as editing files or trying to drop and recreate it. These actions can lead to complete service failure and data loss. Another mistake is not having recent backups of master; without them, after a rebuild you must manually reconstruct logins, jobs, and configuration, which is time consuming and error prone. Administrators should also carefully document rebuild procedures and test them in non production environments so that they are prepared for real incidents. Understanding and using the supported setup based rebuild method is key to safe recovery.


Final Answer:
The correct choice is To rebuild the master database in SQL Server you run the SQL Server setup program with the rebuild database option (or equivalent command-line switch) to recreate the system databases, and then restore master from a known good backup and reapply necessary configurations., because it describes the official, supported procedure for recovering from a corrupted master database in SQL Server.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion