You are on page 1of 19

United States (English) Sign in

Home Library Learn Samples Downloads Support Community Forums MSDN Library Servers and Enterprise Development SQL Server SQL Server 2012 Product Documentation Books Online for SQL Server 2012 Database Engine Database Engine Features and Tasks Database Features Databases (Database Engine) System Databases master Database model Database msdb Database Resource Database tempdb Database Rebuild System Databases

Rebuild System Databases


SQL Server 2012 Other Versions

3 out of 7 rated this helpful - Rate this topic System databases must be rebuilt to fix corruption problems in the master, model, msdb, or resource system databases or to modify the default server-level collation. This topic provides step-by-step instructions to rebuild system databases in SQL Server 2012. In This Topic

Before you begin:

Limitations and Restrictions Prerequisites

Procedures: Rebuild System Databases Rebuild the resource Database Create a New msdb Database

Follow Up: Troubleshoot Rebuild Errors

Before You Begin

Limitations and Restrictions


When the master, model, msdb, and tempdb system databases are rebuilt, the databases are dropped and re-created in their original location. If a new collation is specified in the rebuild statement, the system databases are created using that collation setting. Any user modifications to these databases are lost. For example, you may have user-defined objects in the master database, scheduled jobs in msdb, or changes to the default database settings in the model database. [Top]

Prerequisites
Perform the following tasks before you rebuild the system databases to ensure that you can restore the system databases to their current settings. 1. Record all server-wide configuration values.
2. SELECT * FROM sys.configurations;

3. Record all service packs and hotfixes applied to the instance of SQL Server and the current collation. You must reapply these updates after rebuilding the system databases.
4. SELECT 5. SERVERPROPERTY('ProductVersion ') AS ProductVersion, 6. SERVERPROPERTY('ProductLevel') AS ProductLevel, 7. SERVERPROPERTY('ResourceVersion') AS ResourceVersion,

8. SERVERPROPERTY('ResourceLastUpdateDateT ime') AS ResourceLastUpdateDateTime, 9. SERVERPROPERTY('Collation') AS Collation;

10. Record the current location of all data and log files for the system databases. Rebuilding the system databases installs all system databases to their original location. If you have moved system database data or log files to a different location, you must move the files again.
11. SELECT name, physical_name AS current_file_location 12. FROM sys.master_files 13. WHERE database_id IN (DB_ID('master'), DB_ID('model'), DB_ID('msdb'), DB_ID('tempdb'));

14. Locate the current backup of the master, model, and msdb databases. 15. If the instance of SQL Server is configured as a replication Distributor, locate the current backup of the distribution database.
16. Ensure you have appropriate permissions to

rebuild the system databases. To perform this operation, you must be a member of the sysadmin fixed server role. For more information, see Server-Level Roles. 17. Verify that copies of the master, model, msdb data and log template files exist on the local server. The default location for the template files is C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Bi nn\Templates. These files are used during the rebuild process and must be present for Setup to succeed. If they are missing, run the Repair feature of Setup, or manually copy the files from your installation media. To locate the files on the installation media, navigate to the appropriate platform directory (x86 or x64) and then navigate to setup\sql_engine_core_inst_msi\Pfiles\SqlServr\ MSSQL.X\MSSQL\Binn\Templates. [Top] Rebuild System Databases

The following procedure rebuilds the master, model, msdb, and tempdb system databases. You cannot specify the system databases to be rebuilt. For clustered instances, this procedure must be performed on the active node and the SQL Server resource in the corresponding cluster application group must be taken offline before performing the procedure. This procedure does not rebuild the resource database. See the section, "Rebuild the resource Database Procedure" later in this topic.

To rebuild system databases for an instance of SQL Server:


1. Insert the SQL Server 2012 installation media into the disk drive, or, from a command prompt, change directories to the location of the setup.exe file on the local server. The default location on the server is C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Release. 2. From a command prompt window, enter the following command. Square brackets are used to indicate optional parameters. Do not enter the brackets. When using the Windows Vista operating system with User Account Control (UAC) enabled, running Setup requires elevated privileges. The command prompt must be run as Administrator. Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=InstanceName /SQLSYSADMINACCOUNTS=accounts [ /SAPWD= StrongPassword ] [ /SQLCOLLATION=CollationName] Description Specifies that Setup run without any user /QUIET or /Q interface. Specifies that Setup re-create the system /ACTION=REBUILDDATABASE databases. Is the name of the instance of SQL Server. For /INSTANCENAME=InstanceName the default instance, enter MSSQLSERVER. /SQLSYSADMINACCOUNTS=accounts Specifies the Windows groups or individual accounts to add to the sysadmin fixed server role. When specifying more than one account, separate the accounts with a blank space. For example, enter BUILTIN\Administrators MyDomain\MyUser. When you are specifying an account that contains a blank space within Parameter name

the account name, enclose the account in double quotation marks. For example, enter NT AUTHORITY\SYSTEM. Specifies the password for the SQL Server sa account. This parameter is required if the instance uses Mixed Authentication (SQL Server and Windows Authentication) mode. [ /SAPWD=StrongPassword ] Security Note The sa account is a well-known SQL Server account and it is often targeted by malicious users. It is very important that you use a strong password for the sa login. Do not specify this parameter for Windows Authentication mode. Specifies a new server-level collation. This parameter is optional. When not specified, the current collation of the server is used.

Important Changing the server-level collation does not [ /SQLCOLLATION=CollationName ] change the collation of existing user databases. All newly created user databases will use the new collation by default. For more information, see Set or Change the Server Collation. 3. When Setup has completed rebuilding the system databases, it returns to the command prompt with no messages. Examine the Summary.txt log file to verify that the process completed successfully. This file is located at C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Logs. Post-Rebuild Tasks After rebuilding the database you may need to perform the following additional tasks:

Restore your most recent full backups of the master, model, and msdb databases. For more information, see Back Up and Restore of System Databases (SQL Server).

Important If you have changed the server collation, do not restore the system databases. Doing so will replace the new collation with the previous collation setting. If a backup is not available or if the restored backup is not current, re-create any missing

entries. For example, re-create all missing entries for your user databases, backup devices, SQL Server logins, end points, and so on. The best way to re-create entries is to run the original scripts that created them. Security Note We recommend that you secure your scripts to prevent their being altered by unauthorized by individuals. If the instance of SQL Server is configured as a replication Distributor, you must restore the distribution database. For more information, see Back Up and Restore Replicated Databases.

Move the system databases to the locations you recorded previously. For more information, see Move System Databases. Verify the server-wide configuration values match the values you recorded previously.

[Top] Rebuild the resource Database The following procedure rebuilds the resource system database. When you rebuild the resource database, all service packs and hot fixes are lost, and therefore must be reapplied.

To rebuild the resource system database:


1. Launch the SQL Server 2012 Setup program (setup.exe) from the distribution media. 2. In the left navigation area, click Maintenance, and then click Repair. 3. Setup support rule and file routines run to ensure that your system has prerequisites installed and that the computer passes Setup validation rules. Click OK or Install to continue. 4. On the Select Instance page, select the instance to repair, and then click Next. 5. The repair rules will run to validate the operation. To continue, click Next.

6. From the Ready to Repair page, click Repair. The Complete page indicates that the operation is finished. [Top] Create a New msdb Database If the msdb database is damaged and you do not have a backup of the msdb database, you can create a new msdb by using the instmsdb script. Caution Rebuilding the msdb database using the instmsdb script will eliminate all the information stored in msdb such as jobs, alert, operators, maintenance plans, backup history, Policy-Based Management settings, Database Mail, Performance Data Warehouse, etc. 1. Stop all services connecting to the Database Engine, including SQL Server Agent, SSRS, SSIS, and all applications using SQL Server as data store. 2. Start SQL Server from the command line using the command: NET START MSSQLSERVER /T3608 For more information, see Start, Stop, Pause, Resume, Restart the Database Engine, SQL Server Agent, or SQL Server Browser Service. 3. In another command line window, detach the msdb database by executing the following command, replacing <servername> with the instance of SQL Server: SQLCMD -E -S<servername> -dmaster -Q"EXEC sp_detach_db msdb" 4. Using the Windows Explorer, rename the msdb database files. By default these are in the DATA sub-folder for the SQL Server instance. 5. Using SQL Server Configuration Manager, stop and restart the Database Engine service normally. 6. In a command line window, connect to SQL Server and execute the command: SQLCMD -E -S<servername> -i"C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Ins tall\instmsdb.sql" -o" C:\Program Files\Microsoft

SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Ins tall\instmsdb.out" Replace <servername> with the instance of the Database Engine. Use the file system path of the instance of SQL Server. 7. Using the Windows Notepad, open the instmsdb.out file and check the output for any errors. 8. Re-apply any service packs or hotfix installed on the instance. 9. Recreate the user content stored in the msdb database, such as jobs, alert, etc. 10. Backup the msdb database. [Top] Troubleshoot Rebuild Errors Syntax and other run-time errors are displayed in the command prompt window. Examine the Setup statement for the following syntax errors:

Missing slash mark (/) in front of each parameter name. Missing equal sign (=) between the parameter name and the parameter value. Presence of blank spaces between the parameter name and the equal sign. Presence of commas (,) or other characters that are not specified in the syntax.

After the rebuild operation is complete, examine the SQL Server logs for any errors. The default log location is C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Logs. To locate the log file that contains the results of the rebuild process, change directories to the Logs folder from a command prompt, and then run findstr /s RebuildDatabase summary*.*. This search will point you to any log files that contain the results of rebuilding system databases. Open the log files and examine them for relevant error messages.

Not quite what you are looking for? You may want to try: Database performance optimization part 2 (Index maintenance) Configuring SQL Server Accent-Insensitivity highlights off 9,984,194 members (61,289 online) Sign in

home articles
o

Chapters and Sections>

o o o o o o o o o o

Search Latest Articles Latest Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip
rebuild master

o o

Post your Blog

quick answers
o o o o o o o o o

Ask a Question View Unanswered Questions View All Questions... C# questions ASP.NET questions VB.NET questions C#4.0 questions C++ questions

discussions
o o

All Message Boards... Application Lifecycle>


Running a Business Sales / Marketing Collaboration / Beta Testing Work & Training Issues

o o o o

Design and Architecture ASP.NET JavaScript C / C++ / MFC>


ATL / WTL / STL Managed C++/CLI

Adobe Technologies

o o o o o o

C# Free Tools Objective-C Ruby On Rails Database Hardware & Devices>

System Admin

o o o o o o o o o o o

Hosting and Servers Java .NET Framework Mobile VS 2012 & .NET 4.5 Sharepoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions

features
o o o o o o o

Component & Service Catalog Competitions News The Insider Newsletter Newsletter archive Surveys Product Showcase

o o o

Research Library CodeProject Stuff

community
o o o o o o o o o

The Insider News The Lounge The Weird & The Wonderful The Soapbox Press Releases Who's Who Most Valuable Professionals Company Listings Non-English Language >

General Indian Topics General Chinese Topics

help
o o o o o o o o o o

What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us Employment Opportunities About Us

Articles Database Database SQL Server Next Tip Browse Code Stats Revisio ns (3) By Kareem.S, 1 Feb 2013 Alternat 4.00 (1 vote) ives Comme nts & Introduction Discussi ons (4) In this tip I would like to show you how to rebuild the master/system About Article This article shows case study, how to rebuild master database Tip/Tri Type ck Licence CPOL First 1 Feb Posted 2013 Views 6,613 database in SQL Server 2008 R2. Recently I faced a problem related to Bookmar 2 times the master database. My instance was unable to start due to master file ked

Rebuilding master database in SQL Server

corruption.

Case Study:

SQLDBABegin ner Intermediate

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 Top News SQL Server ERRORLOG. Please go through the following steps. Step1: Check the error log where it is showing master was corrupted. The History of CTRL + ALT + DELETE Get the Insider News free each morning. Related Videos Step2: 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 Related Articles Database performance optimization part

2 (Index maintenance) Configuring SQL Server AccentInsensitivity Speeding up database access Part 7: Fixing Step3: Once the above command runs successfully, check in the fragmentation summary.txt file as follows and look at the Requested action. Evaluating SQL Server Data Tools Backup System Databases in SQL Server How to Fix Orphaned SQL Users One to Many Reports with VS.NET 2005 (2.0) Report Step4: Start SQL Server service. Designer Top 10 steps to optimize data access in SQL Server: Part I Step5: Connect to the instance. But you cannot see any user defined (use indexing) databases. The rebuilding process has created a fresh master database MySQL so there are no other databases and all previous configuration values Database Replication are lost. Procedure Find particular word or text from the entire stored procedure Transparent Database Encryption Tool KeePass Password Safe Creating Master Detail representation of data display in

Winforms using LINQ (C#) Step7: Now we can restore the master database to get the previous configuration settings. Go to command prompt and run server in single Hands on how to configure the user mode as follows Microsoft MSDE Rebuild and Reorganizing the index on SQL Server Master Pages and Windows SharePoint Services 3.0 Database Snapshot in MS Step8: Connect to the instance and take new query to restore master SQL Server database. Once we restore master database then we can get all the Large Log File previous configuration values including user defined databases. SQL 2005 Dude, where's my business logic? MyMDb your local IMDB store

Step9: Click on Connect button and connect to the instance as follows

Step10: Restore master database as follows

Step11: Restart SQL Server instance in multi user mode and connect to SQL Server Management Studio. We can see all user databases as follows.

Happy learning!

License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Kareem.S Instructor / Trainer OptimizeSQL Technologies India Mr. Kareem Syed is a senior SQL Server Trainer and working as Technical Consultant. You can visit my blog at www.optimizesql.blogspot.in

Follow on Article Top

Twitter

Sign Up to vote Poor

Excellent

Comments and Discussions


You must Sign In to use this message board. Search this forum Spacing Noise Layout Per page First Prev Next very very good yahya_iranmanesh 26-Jun-13 23:47 thank you for your solution. its very very good. Sign InView ThreadPermalink Great guide Member 10049488 13-May-13 10:42 It's a very good guide. Pls keep helping the community. Thanks Sign InView ThreadPermalink One another solution Adam Gorge 17-Feb-13 23:22 One another solution to fix master database corruption is to use of third party tools. These tools are specially design to repair corrupt SQL Server database. SQL Server Database Recovery Software is not even repair corrupt SQL Server database but also repair all corrupted SQL Server database objects. Sign InView ThreadPermalink 1.00/5 (1 vote) The formatting... OriginalGriff 31-Jan-13 8:18 ...of your text is bad enough, but why is the formatting of the text in your images equally all over the place? If you are going to post images, try to make sure that they all look like they were taken on the same computer?
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

Profile popups

Sign InView ThreadPermalink 5.00/5 (2 votes) Last Visit: 31-Dec-99 18:00 Last Update: 24-Jul-13 5:46 Refresh 1 General News Suggestion Question Bug Answer Joke Rant Admin Permalink | Advertise | Privacy | Mobile Web03 | 2.6.130723.1 | Last Updated 1 Feb 2013

Article Copyright 2013 by Kareem.S Everything else Copyright CodeProject, 1999-2013 Terms of Use Layout: fixed | fluid

You might also like