Thank this author by sharing:
By Christoffer Hedgate, 2004/11/30
Moving a database in SQL Server is normally as simple as detaching it from the server, moving it to it's new location and then attaching it again. However, that only counts for user databases. Moving system databases requires quite a bit more work. Since I had to do this a couple of times during the last weeks I wrote down a simple checklist that I could follow to make sure it was done right, so I did not screw up the servers and could speed up the process as much as possible. And, since I guess I will be doing it again sometime in the future and inevitably will lose the notes I scribbled down, I thought I could just as well post them here for safe-keeping. If anyone wants to use this checklist go ahead, but remember to do the steps in the exact order of the list, and make sure you have all the necessary backups before starting. To be completely clear, doing this wrong can completely screw up your databases and I can not take any responsibility if anything does go wrong. Also note that the checklist was written for the specific situation I was encountered with. Your system databases might have more data files and/or other file paths and names than those in the list, so you might need to make some changes. Have fun!
------------- use master go exec sp_detach_db 'msdb' go exec sp_detach_db 'model' go -------------
------------- use master go exec sp_attach_db 'model' , 'PATH_TO_MODEL_DATAFILE\model.mdf' , 'PATH_TO_MODEL_LOGFILE\modellog.ldf' go -------------
------------- use model go exec sp_helpfile go -------------
------------- use master go exec sp_attach_db 'msdb' , 'PATH_TO_MSDB_DATAFILE\msdbdata.mdf' , 'PATH_TO_MSDB_LOGFILE\msdblog.ldf' go -------------
------------- use msdb go exec sp_helpfile go -------------
------------- use master go alter database tempdb modify file (name = tempdev , filename = 'PATH_TO_NEW_LOCATION_OF_TEMPDB_DATAFILE\tempdb.mdf') go alter database tempdb modify file (name = templog , filename = 'PATH_TO_NEW_LOCATION_OF_TEMPDB_DATAFILE\templog.ldf') go -------------
------------- use tempdb go exec sp_helpfile go -------------
------------- use tempdb go create table test (a int) insert into test (a) values (1) select * from test drop table test go -------------
OLD_PATH_TO_MASTER_MDFFILE\master.mdf --> NEW_PATH_TO_MASTER_MDFFILE\master.mdf OLD_PATH_TO_MASTER_LOGFILE\Data\mastlog.ldf --> NEW_PATH_TO_MASTER_LOGFILE\mastlog.ldf OLD_PATH_TO_SQL_DATA_LOCATION\BACKUP --> NEW_PATH_TO_SQL_DATA_LOCATION (the entire folder with everything in it) OLD_PATH_TO_SQL_DATA_LOCATION\JOBS --> NEW_PATH_TO_SQL_DATA_LOCATION (the entire folder with everything in it) OLD_PATH_TO_SQL_DATA_LOCATION\LOG --> NEW_PATH_TO_SQL_DATA_LOCATION (the entire folder with everything in it) OLD_PATH_TO_SQL_DATA_LOCATION\REPLDATA --> NEW_PATH_TO_SQL_DATA_LOCATION (the entire folder with everything in it)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer BackupDirectory = NEW_PATH_TO_SQL_DATA_LOCATION\BACKUP HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Replication WorkingDirectory = NEW_PATH_TO_SQL_DATA_LOCATION\REPLDATA HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Setup SQLDataRoot = NEW_PATH_TO_SQL_DATA_LOCATION\ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent ErrorLogFile = NEW_PATH_TO_SQL_DATA_LOCATION\LOG\SQLAGENT.OUT WorkingDirectory = NEW_PATH_TO_SQL_DATA_LOCATION\JOBS
So there we are, all system databases moved. Again, please note that this was mainly meant as a checklist for myself, but feel free to use it as a base for your own checklist when you need to move system databases. I urge you to read through it several times so you are sure what it says and what you are doing. Most of the steps here come from the Microsoft article Moving SQL Server databases to a new location with Detach/Attach, which will probably help you more than this list. I simply compiled them into an easy-to-follow, step-by-step list that I could use to cut the down-time as much as possible.
When you create a new database in SQL Server without explicitly specifying database file locations, ...
Database Default Locations in Database Setting Under Server Properties
Few months back I have wrote post about moving MASTER and MSDB database to new location in stand alo...
Move Master database from the 2000 to 2005 SQL server
SQL Server table backups location
As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.
Join us!
Steve Jones Editor, SQLServerCentral.com