SQL SERVER MOVING SYSTEM DATABASES, movingdatabases
You might need to move system databases as part of a planned relocation or scheduled maintenance
Operation. If you move a system database and later rebuild
MasterDatabase, you must move that
System database again because the rebuild operation installsystem databases to their default
Location. The steps for moving
Tempdb,
Model, And
MsdbAre slightly different than for moving
MasterDatabase.
Note
In SQL Server 2012,
Mssqlsystemresource
Database can't be moved. If you move
The fies for this database, you can't be able to restart your SQL Server service.
Here are the steps for moving an undamaged system database (other than the master database ):
1. For each fie in the database to be moved, use
ALTER DATABASECommand with
MODIFY FILEOption to specify the new physical location.
2. Stop the SQL Server instance.
3. Physically move the fies.
4. Restart the SQL Server instance.
5. Verify the change by running the following query:
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys. master_files
WHERE database_id = DB_ID (n' <database_name> ');
If the system database needs to be moved because of
Hardware failure, The solution is a bit more
Problematic because you might not have access to the server to run
ALTER DATABASECommand.
Follow these steps to move a damaged system database (other than
MasterDatabase or
Resource database ):
1. Stop the instance of SQL Server if it has been started.
2. Start the instance of SQL Server in
Master-
OnlyRecovery mode (by specifying
Traceflg 3608)
By entering one of the following commands at the command prompt:
-- If the instance is the default instance:
Net start mssqlserver/f/T3608
-- For a named instance:
Net start mssql $ instancename/f/T3608
/FIndicates that the instance of SQL Server starts with minimal confiuration.
CHAPTER 4Special databases
143
3. For each fie in the database to be moved, use
ALTER DATABASECommand with
MODIFY FILEOption to specify the new physical location. You can use either Management Studio or
SQLCMDUtility.
4. Exit Management Studio or
SQLCMDUtility.
5. Stop the instance of SQL Server.
6. Physically move the fie or fies to the new location.
7. Restart the instance of SQL Server without traceflg 3608. For example, run
NET START
MSSQLSERVER.
8. Verify the change by running the following query:
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys. master_files
WHERE database_id = DB_ID (n' <database_name> ');
- Moving the master database
Full details on moving
MasterDatabase can be found in
SQL Server Books Online,But the steps are
Summarized here. The biggest difference between moving this database and moving other system
Databases is that you must go through the SQL Server Confiuration Manager.
To move
MasterDatabase, followw these steps.
1. Open the SQL Server Confiuration Manager. Right-click the desired instance of SQL Server,
Choose Properties, and then click the Startup Parameters tab.
2. Edit the Startup Parameters values to point to the new directory location for
Master
Database data and log fies and click Update. If you want, you can also move the SQL Server
Error log fies. The parameter value for the data fie must follow
-DParameter, the value
For the log fie must follow
-LParameter, and the value for the error log must follow
-E
Parameter, as shown here:
-DE: \ Data \ master. mdf
-LE: \ Data \ mastlog. ldf
-EE: \ Data \ LOG \ ERRORLOG
3. Stop the instance of SQL Server and physically move the fies for the new location.
4. Restart the instance of SQL Server.
5. Verify the fie change for
MasterDatabase by running the following query:
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys. master_files
WHERE database_id = DB_ID ('master ');
144Microsoft SQL Server 2012 Internals
Finally, if you are also changing your drive letters or folders, you need to verify and perhaps
Change the location of the SQL Server Agent error log fie and the confiured database default
Locations setting. The Database default locations setting is defied on Server Properties | Database
Settings.