SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


move db files to another directory


move db files to another directory

Author
Message
sqlfriends
sqlfriends
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5040 Visits: 4075
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
Leo.Miller
Leo.Miller
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1354 Visits: 1537
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
Perry Whittle
Perry Whittle
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26591 Visits: 17335
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" ;-)
sqlfriends
sqlfriends
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5040 Visits: 4075
Thanks much, will give it a try
sqlfriends
sqlfriends
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5040 Visits: 4075
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
Perry Whittle
Perry Whittle
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26591 Visits: 17335
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" ;-)
george sibbald
george sibbald
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13002 Visits: 13695
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.

---------------------------------------------------------------------
sqlfriends
sqlfriends
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5040 Visits: 4075
Thanks, but it seems detach and attach is easier and involves less steps to do.
george sibbald
george sibbald
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13002 Visits: 13695
Not enough to worry about! the alter database command was designed for just such tasks and is the safest way.

---------------------------------------------------------------------
Perry Whittle
Perry Whittle
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26591 Visits: 17335
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" ;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search