# MsSQL - Restore Master/Model/MSDB

Steps to Restore the `master` Database:

- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad"><span data-huuid="7828366274802587318">**Stop the SQL Server Instance:**</span></div><div class="vM0jzc">
    - <span data-huuid="7828366274802589319">Open SQL Server Configuration Manager or Windows Services.</span>
    - <span data-huuid="7828366274802586557">Locate the SQL Server service (e.g., `SQL Server (MSSQLSERVER)` for a default instance).</span>
    - <span data-huuid="7828366274802587891">Stop the service.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad"><span data-huuid="7828366274802589225">**Start SQL Server in Single-User Mode:**</span></div><div class="vM0jzc">
    - <span data-huuid="7828366274802587130">Open the SQL Server service properties (e.g., by double-clicking the service in Services).</span>
    - <span data-huuid="7828366274802588464">Go to the "Startup Parameters" tab.</span>
    - <span data-huuid="7828366274802585702">Add `-m` (for single-user mode) to the existing startup parameters. </span><span data-huuid="7828366274802586369">If there are existing parameters, separate them with a semicolon.</span>
    - <span data-huuid="7828366274802587703">Start the SQL Server service from there</span>
    
    </div></div></div></div>

[![image.png](https://docs.sflservicesllc.com/uploads/images/gallery/2025-09/scaled-1680-/PJaimage.png)](https://docs.sflservicesllc.com/uploads/images/gallery/2025-09/PJaimage.png)

- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad"><span data-huuid="7828366274802589037">Connect using `sqlcmd`:</span></div><div class="vM0jzc">
    - <span data-huuid="7828366274802586942">Open a new Command Prompt window as Administrator.</span>
    - <span data-huuid="7828366274802588276">Navigate to the SQL Server Binn directory (e.g., `C:\Program Files\Microsoft SQL Server\MSSQLXX.MSSQLSERVER\MSSQL\Binn`).</span>
    - <span data-huuid="7828366274802589610">Connect to the SQL Server instance using `sqlcmd` in single-user mode. </span><span data-huuid="7828366274802586181">For a default instance, use:</span>
    
    </div></div></div></div>```mssql
    sqlcmd -S . -E -d master
    sqlcmd -S . -U sa - P PASSWORD -d master
    ```

<span data-huuid="4812136605183709334">For a named instance, replace `.` </span><span data-huuid="4812136605183711883">with `.\<InstanceName>`</span>

<div class="WaaZC" id="bkmrk-restore-the%C2%A0master%C2%A0d"><div class="RJPOee EIJn2">- <span data-huuid="4812136605183711338">Restore the `master` Database:</span>
    - <span data-huuid="4812136605183710793">In the `sqlcmd` prompt, execute the following `RESTORE DATABASE` command, replacing `<path_to_backup_file>` with the actual path to your `master` database backup file:</span>

</div></div>```
RESTORE DATABASE master FROM DISK = '\\192.168.1.61\Backups\UNIBCESRV02\master\FULL\UNIBCESRV02_master_FULL_20250910_010011.bak' WITH REPLACE, RECOVERY;
RESTORE DATABASE model FROM DISK = '\\192.168.1.61\Backups\UNIBCESRV02\model\FULL\UNIBCESRV02_model_FULL_20250910_010013.bak' WITH REPLACE, RECOVERY;
RESTORE DATABASE msdb FROM DISK = '\\192.168.1.61\Backups\UNIBCESRV02\msdb\FULL\UNIBCESRV02_msdb_FULL_20250910_010014.bak' WITH REPLACE, RECOVERY;
```

<span data-huuid="2191367519031566043">Check integrity  
</span>

```
DBCC CHECKDB ('master') WITH ALL_ERRORMSGS, EXTENDED_LOGICAL_CHECKS;
```

- <span data-huuid="2191367519031566043">The `WITH REPLACE` option is crucial as it overwrites the existing `master` database.</span>
- <span data-huuid="2191367519031565045">The `RECOVERY` option brings the database online after the restore.</span>
- <span data-huuid="2191367519031566043">**Restart SQL Server in Normal Mode:**</span>
    - <span data-huuid="1128839973215708518">After the restore completes and `sqlcmd` indicates the instance is shutting down, stop the SQL Server service again.</span>
    - <span data-huuid="1128839973215708704">Remove the `-m` startup parameter from the SQL Server service properties.</span>
    - <span data-huuid="1128839973215708890">Start the SQL Server service normally.</span>
- 