Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

move db files to another directory Expand / Collapse
Author
Message
Posted Tuesday, December 4, 2012 6:16 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 10:06 AM
Points: 1,792, Visits: 3,261
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
Post #1392759
Posted Tuesday, December 4, 2012 6:41 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, November 9, 2014 7:56 PM
Points: 450, Visits: 1,343
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
Post #1392762
Posted Wednesday, December 5, 2012 2:04 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:00 AM
Points: 6,741, Visits: 14,373
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"
Post #1392841
Posted Wednesday, December 5, 2012 9:44 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 10:06 AM
Points: 1,792, Visits: 3,261
Thanks much, will give it a try
Post #1393093
Posted Wednesday, December 5, 2012 9:53 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 10:06 AM
Points: 1,792, Visits: 3,261
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
Post #1393098
Posted Wednesday, December 5, 2012 10:03 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:00 AM
Points: 6,741, Visits: 14,373
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"
Post #1393107
Posted Wednesday, December 5, 2012 10:06 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:38 AM
Points: 5,888, Visits: 13,060
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.


---------------------------------------------------------------------

Post #1393109
Posted Wednesday, December 5, 2012 10:46 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 10:06 AM
Points: 1,792, Visits: 3,261
Thanks, but it seems detach and attach is easier and involves less steps to do.
Post #1393130
Posted Wednesday, December 5, 2012 11:10 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:38 AM
Points: 5,888, Visits: 13,060
Not enough to worry about! the alter database command was designed for just such tasks and is the safest way.

---------------------------------------------------------------------

Post #1393140
Posted Wednesday, December 5, 2012 12:16 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:00 AM
Points: 6,741, Visits: 14,373
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"
Post #1393164
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse