|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 12:36 PM
Points: 1,605,
Visits: 2,786
|
|
I would like to move database files to another drive. I used sql like below: ALTER DATABASE Z_20090501_coreSPSS MODIFY FILE ( NAME = coreSPSS, FILENAME = 'G:\DetachedArchiveDatabase\Z_20090501_coreSPSS.mdf'); GO ALTER DATABASE Z_20090501_coreSPSS MODIFY FILE ( NAME = coreSPSS_log, FILENAME = 'G:\DetachedArchiveDatabase\Z_20090501_coreSPSS_log.ldf'); GO The file "coreSPSS" has been modified in the system catalog. The new path will be used the next time the database is started. The file "coreSPSS_log" has been modified in the system catalog. The new path will be used the next time the database is started.
But when I look at the G directory, the files are not there Why is that?
Thanks
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Yesterday @ 8:07 PM
Points: 442,
Visits: 1,301
|
|
This only moves the logical location of the files. To actually get them to the new location you need to take the database off line in some way so you can move the physical files.
Either stop SQL, or take the DB off line, then copy/move the files and start SQL or bring the DB back on line.
Leo
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:53 AM
Points: 5,204,
Visits: 11,158
|
|
Stopping sql server is a bit like using a sledge hammer to crack a nut. You only need to take the database offline as follows
ALTER DATABASE mydb SET OFFLINE
- Once offline, copy the disk files to the new locations.
- Bring the database online.
- When the database comes online successfully delete the old files.
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 12:36 PM
Points: 1,605,
Visits: 2,786
|
|
| Thanks much, will give it a try
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 12:36 PM
Points: 1,605,
Visits: 2,786
|
|
By the way, what is the difference by take offline, then copy to anther directory , then bring online with detach the database, copy to another directory, then attach it.
Which is better way?
Thanks
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:53 AM
Points: 5,204,
Visits: 11,158
|
|
they both achieve the same result. Detaching removes the database from the system catalogs whereas offline doesn't.
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:22 AM
Points: 5,269,
Visits: 11,207
|
|
Alter database is the preferred method of doing this. Its safer as the database is never actually removed form the instance so any risk when reattaching is mitigated. Also when you reattach the owner of the database could change, which may cause you an issue.
Whatever way you do it (and it can be done via backup\restore) having a backup to go back to is sensible.
---------------------------------------------------------------------
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 12:36 PM
Points: 1,605,
Visits: 2,786
|
|
| Thanks, but it seems detach and attach is easier and involves less steps to do.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:22 AM
Points: 5,269,
Visits: 11,207
|
|
Not enough to worry about! the alter database command was designed for just such tasks and is the safest way.
---------------------------------------------------------------------
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:53 AM
Points: 5,204,
Visits: 11,158
|
|
sqlfriends (12/5/2012) Thanks, but it seems detach and attach is easier and involves less steps to do. Do whatever you feel comfortable with, just know that in SQL server 2005 on ALTER DATABASE is the preferred method
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs"
|
|
|
|