Site icon Database Tutorials

Rebuild System Databases in SQL Server

 

Because of the problems that occur in the system databases, it is sometimes necessary to rebuild. Rebuild operation resets system databases and allows the system to be opened cleanly. But since the rebuild process will reset all the data in the system databases, you must first make sure that you have the latest backups of the system databases.

If you rebuild your system databases while you have no backup, you will lose all your logins and jobs. And you can’t see your databases on instance when you open instance. Your Instance will be like a newly installed instance.

However, you can add your databases to this new instance by attaching the database files. You can find out how to attach your database files in the article “How To Change The Disk Of Database Files On SQL Server(Detach Attach & Backup Restore Methods)“.

Below, I explained what should be done before and after the rebuild and the effects of the rebuild process;

So how to rebuild the system databases?

First, you must have the sql server setup file on the server. You should then run the cmd command prompt as administrator.

Then on the cmd command prompt, go to the path where the sql server setup file is.

You should then run the following script. You can also use the following script to change the server collation in an instance. But as I mentioned above, note that these operations will reset all the information on the instance.

After reboot is finished, you will find an empty instance when you open instance. After this stage, you will restore the master, model and msdb databases one by one or perform the operations described in this article.

To perform the restore of the master database;

I suggest you read my articles “Restore master database in SQL Server“. You should also restore your msdb and model databases.

You can perform the restore operations of the msdb and model database as normal database restore. There is no extra setting. To restore the msdb database, you must stop the SQL Server Agent Service from SQL Server Configuration Manager.

You can find the restore scripts of msdb and model system databases below.

Restore model database;

Restore msdb database;

If you don’t have backups of the model and msdb databases, stop the sql server service and paste the files you copied before the rebuild onto the existing msdb and model database files(overwrite, but always take backup of every thing). When you open the service again, you can see your jobs. But I would like to point out that the most healthy method is to return from backup.

Note: You can not restore tempdb database. Because the tempdb database is re-created by the sql server each time after the SQL Server service starts. You may want to read the article “How To Move The Tempdb Database To Another Disk

Exit mobile version