Tuesday, 26 February 2013

SQL Server - Rebuilding the Master Databse

To change the default collation for SQL Server it is necessary to rebuild the master database. For full details of how to do this check out the MSDN link. The following gives a brief summary of the steps involved.Run the following command from the SQL Server setup media directory:
Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=domain\account /SAPWD=SApassword /SQLCOLLATION=Latin1_General_CI_AS
Check the location of the physical data files:
SELECT name, physical_name AS current_file_locationFROM sys .master_filesWHERE database_id IN (DB_ID ('master'), DB_ID( 'model'), DB_ID('msdb' ), DB_ID('tempdb' ));
Move the tempdb files if required:
USE master ;GOALTER DATABASE tempdbMODIFY FILE (NAME = tempdev, FILENAME = 'F:\MSSQLData\tempdb.mdf');GOALTER DATABASE tempdbMODIFY FILE (NAME = templog, FILENAME = 'F:\MSSQLLogs\templog.ldf');GO
Once the files have been moved and the service restarted then the tempdb files created during the rebuild can be removed from the old location.You may want to disable the sa account:
ALTER LOGIN sa DISABLE;