Skip to main content

Free demo previews every object and exports 25 records per table.

PCVITA Logo
SQL Server

How to Rebuild Master Database in SQL Server?

  • Mohit JhaPublished ByMohit Jha
  • Tej Pratap ShuklaApproved ByTej Pratap Shukla
  • Published
  • Updated
  • Reading Time7 min
Quick Answer

Rebuild master database in SQL Server when the instance fails to start. You get 3 methods in this guide. Method 1 rebuilds the system databases with Setup. Method 2 restores your master and msdb backups. Method 3 recovers user databases with PCVITA software. Record your settings and copy your files first.

Your SQL Server instance stops at startup and the error log points to the master database. Every login, linked server and database entry of the instance lives in that one database.

This guide shows how to rebuild master database in SQL Server with 3 methods. Steps follow the Microsoft Learn page on rebuilding system databases.

Why Rebuild Master Database in SQL Server?

SQL Server marks a database as SUSPECT when the primary filegroup is damaged and recovery fails at startup. Microsoft states that such a database stays unavailable until you act. Damage to master stops the entire instance.

  • Startup failure. SQL Server does not start and the error log names the master database.
  • Disk faults. Bad sectors or a failing disk damage the master data file.
  • Power loss. Sudden shutdown during a write leaves the file inconsistent.
  • Lost files. Someone deletes or moves the master files by mistake.
Do You Know?

Setup recreates the four system databases in their original locations. It does not rebuild the resource database. Microsoft uses the Repair feature of Setup for that one.

What to Record Before You Rebuild (Checklist)

The rebuild drops your changes in all four system databases. Collect the facts below while the instance still starts. Without a working instance use your own documentation.

  1. Record the configuration. Execute SELECT * FROM sys.configurations; and save the result.
  2. Record version and collation. Query SERVERPROPERTY for ProductVersion, ProductLevel and Collation. You reapply updates later.
  3. Record file locations. Query sys.master_files for all four system databases. Setup resets the files to their original locations.
  4. Locate your backups. Find the newest full backups of master and its two companions.
  5. Check the template files. Setup needs them in the Binn\Templates folder of your instance. Copy them from the installation media when they are missing.
  6. Copy your user database files. Save every MDF, NDF and LDF file to another disk.

Method #1: Rebuild System Databases With Setup (Free, Microsoft Command)

Setup rebuilds all four system databases in one step. You need membership in the sysadmin fixed server role and an elevated Command Prompt.

  1. Mount the SQL Server installation media or open the folder that holds setup.exe. SQL Server 2022 keeps it in C:\Program Files\Microsoft SQL Server\160\Setup Bootstrap\SQLServer2022.
  2. Right click Command Prompt and select Run as Administrator.
  3. Execute the command below. Replace the instance name and the accounts with your values.
setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=Domain\Account
  • Instance name. Use MSSQLSERVER for the default instance.
  • Accounts. Separate several accounts with a space and place quotes around a name that has a space.
  • Password. Add /SAPWD only for Mixed Authentication mode.
  • Collation. Add /SQLCOLLATION to set a new collation. Setup keeps the current collation without it.
  1. Wait for Setup to return to the prompt. It prints no message when it finishes.
  2. Open Summary.txt in C:\Program Files\Microsoft SQL Server\160\Setup Bootstrap\Logs and confirm the result.
Heads Up

A missing slash or equals sign makes Setup fail. Microsoft asks you to check the syntax first. Number 160 belongs to SQL Server 2022. Your version uses another number.

Method #2: Restore Master, Model and MSDB Backups (Free)

A new master database holds none of your logins or database entries. Restore your backups to bring them back.

  1. Restore the latest full backups of the three databases.
  2. Skip the restore when you changed the server collation. Backups bring the old collation back.
  3. Recreate logins, backup devices and endpoints from your own scripts when no backup exists.
  4. Restore the distribution database when the instance is a replication distributor.
  5. Move the system database files to the locations you recorded.
  6. Reapply every hotfix and cumulative update and compare the settings with your saved sys.configurations list.

Attach your user database files again when the master backup does not list them. Use CREATE DATABASE ... FOR ATTACH and point to the MDF and NDF files.

Method #3: Recover User Databases With PCVITA Software (Paid Export)

Use this method when a user database fails to attach or stays SUSPECT after the rebuild. PCVITA SQL Database Recovery Tool does not rebuild master. PCVITA software opens the damaged MDF file with its NDF files and brings the data back.

  • No SQL Server needed. The software scans files on any Windows machine.
  • Two scan modes. Quick Scan handles normal corruption and Advance Scan handles severe damage.
  • Deleted records. Recovered records show in red in the preview.
  • Three outputs. Export to a live SQL Server database, a SQL script or CSV files.
  • Version range. The software reads files of SQL Server 2000 to 2025.
PCVITA SQL Database Recovery ToolRepair MDF and NDF files and export the data.
Version 14.0 for Windows. 30 day money back guarantee.
  1. Install PCVITA SQL Database Recovery Tool and click Open. Select the damaged MDF file.

Main screen of the SQL Database Recovery Tool with the Open option

  1. Select Quick Scan or Advance Scan.

Scan mode screen with Quick Scan and Advance Scan options

  1. Keep Auto detect ticked and open the NDF Options tab. Click Add Files when the software misses a secondary file.

NDF Options tab with automatic detection and the Add Files option

  1. Save the scan as a .str file and browse the tables and procedures in the preview.

Preview screen with the object tree and deleted records in red

  1. Click Export and select SQL Server Database, SQL Server Compatible Scripts or CSV File Format.

Export options screen with SQL Server Database, SQL Server Compatible Scripts and CSV File Format

  1. Select With Only Schema or With Schema and Data and click Export.

Export screen with the With Schema and Data option and the deleted records checkboxes

Pro Tip

The free demo exports 25 records per table. Test one table and compare the records with your backup before you buy the full edition.

Which Method Fits Your Case?

MethodWorks WhenRisk to DataCost
#1 Setup RebuildMaster is damaged and the instance failsDrops your changes in system databasesFree
#2 Restore BackupsYou hold current system backupsLow after the rebuildFree
#3 Recover FilesA user database is damagedNone to the original filesFree demo, $249 full

Safe Handling Tips

  • Copy before you start. Save the MDF, NDF and LDF files of every database on another disk.
  • Test on a spare server. Practice the command on a test instance first.

FAQs About Rebuilding Master Database

Can I rebuild master database in SQL Server without a backup?

Yes. Setup rebuilds the system databases without a backup. You lose user objects in master and jobs in msdb. Microsoft says you recreate logins and databases from your own scripts.

Does a rebuild delete my user databases?

No. Setup rebuilds only the four system databases. Your user database files stay on the disk. The new master does not list them so you restore a master backup or attach the files again.

Can I rebuild only the master database?

No. Microsoft states that the rebuild procedure recreates all four system databases together and you cannot select one of them.

Which permission do I need for the rebuild?

You need membership in the sysadmin fixed server role. On Windows with User Account Control you also open the Command Prompt as Administrator.

How do I confirm that the rebuild worked?

Open the Summary.txt file in the Setup Bootstrap Logs folder of your SQL Server version. Setup prints no message in the Command Prompt when it finishes.

Does PCVITA SQL Database Recovery Tool rebuild master database?

No. The software recovers tables, views, procedures and records from damaged user database files. It exports them to a live SQL Server database, a SQL script or CSV files.

Is there a free demo of PCVITA SQL Database Recovery Tool?

Yes. The free demo previews every object and exports 25 records per table. The full edition costs $249 for one licence and has no record limit.

Closing Words

A damaged master database needs a rebuild because the instance cannot start without it. Record your settings and copy your files first. Execute the Setup command and restore your backups afterward.

  • Methods 1 and 2 use Microsoft commands and recreate the system databases.
  • Method 3 recovers the data of a damaged user database into a new destination.