|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:54 AM
Points: 283,
Visits: 610
|
|
I'm looking to move the database file location from one drive to another on my machine for about 20-30 databases.
Besides a copy/paste of the files from location A to location B and then creating all the databases again and deleting the existing ones, is there any other option?
The file names and database names would be identical, just the path C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLEXP\MSSQL\DATA becomes R:\SQL Monthly Snapshots
I'm guessing I might have to edit the permissions of that folder too to allow Management Studio to write to it?
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:58 PM
Points: 5,204,
Visits: 11,161
|
|
Rob-350472 (9/13/2012) I'm looking to move the database file location from one drive to another on my machine for about 20-30 databases.
Besides a copy/paste of the files from location A to location B and then creating all the databases again and deleting the existing ones, is there any other option?
The file names and database names would be identical, just the path C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLEXP\MSSQL\DATA becomes R:\SQL Monthly Snapshots
I'm guessing I might have to edit the permissions of that folder too to allow Management Studio to write to it?
Something like this for all user databases
SELECT 'ALTER DATABASE ' + QUOTENAME(DB_NAME(database_id)) + ' MODIFY FILE(NAME=' + name + ', FILENAME=N''' + REPLACE(physical_name, 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLEXP\MSSQL\DATA\', 'R:\SQL Monthly Snapshots\') + ''')' FROM sys.master_files WHERE database_id > 4
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:54 AM
Points: 283,
Visits: 610
|
|
Ahh, I see, that makes sense perfectly after delving into that data and seeing what's going on. I can try it with a couple of databases by changing the database_ID and see what happens.
Need to wait till I can actually close Management Studio in the first place (and SQLserver process) to move the files first of all though!
Thanks :)
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:58 PM
Points: 5,204,
Visits: 11,161
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:54 AM
Points: 283,
Visits: 610
|
|
Ah I see, run the command, right click on DB in question, tasks --> take offline.
Copy files in explorer from source to destination
right click --> 'bring online' (at a guess!)
Confirm it works then delete the source files.
Even better!
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 8:44 AM
Points: 4,434,
Visits: 7,218
|
|
I would recommend backing up the databases first, in case the worst happens, which it has done for me before. Given that you have taken a backup, you may want to consider doing the move by RESTOREing WITH MOVE, instead of OFFLINE -> ALTER -> ONLINE. This approach may be quicker if you have large database files with lots of empty space.
John
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:54 AM
Points: 283,
Visits: 610
|
|
Thanks John, I'm currently going through the databases and shrinking them actually. These are monthly archives which are dipped into from time to time and prove very useful. They're not used in production or anything (otherwise I'd not bother shrinking them).
I was just thinking actually that I should get a decent backup routine sorted for these archives, ideally creating a .bak file and compressing then deleting hte .bak file. 7zip perhaps, if not RAR.
The shrink may buy me some more time before I have to move, perhaps I should think of going:
shrink --> backup routine --> move...
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:58 PM
Points: 5,204,
Visits: 11,161
|
|
Rob-350472 (9/13/2012) Ah I see, run the command, right click on DB in question, tasks --> take offline.
Copy files in explorer from source to destination
right click --> 'bring online' (at a guess!)
Confirm it works then delete the source files.
Even better!
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:58 PM
Points: 5,204,
Visits: 11,161
|
|
Rob-350472 (9/13/2012) perhaps I should think of going:
shrink --> backup routine --> move... no, use the method i showed you. backup and restore is a complete waste of time. I use this method all the time even when moving system databases, which by the way is the supported way of moving them.
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:58 PM
Points: 5,204,
Visits: 11,161
|
|
John Mitchell-245523 (9/13/2012) I would recommend backing up the databases first, in case the worst happens, which it has done for me before. Given that you have taken a backup, you may want to consider doing the move by RESTOREing WITH MOVE, Are you serious? Backup and restore to move file paths for databases on the same instance!
Actually its
ALTER -> OFFLINE -> COPY files -> ONLINE
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|