Solved

Movins SQL DB

Posted on 2014-03-17
7
149 Views
Last Modified: 2014-03-18
Hi

I would like to move a database files and the logs files to an other place on my network. An other disk.

What is the best way to do this?

Is it detach and re attache. Or do I have to backup, delete and restore the DB?

I use SQL Server 2008R2

Thank you
0
Comment
Question by:jpmoreau
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39935110
If you don't mind taking the db offline for a bit detach and re-attach will work and is the cleanest.
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 39935672
The cleanest is to ALTER the db properties to the new file locations, put the db offline, physically copy (or move) the files, then bring the db back online.  Since you can use SQL even for the file copies/moves, the entire thing can be scripted.

Detach has far too many side effects -- including changing the security settings, messing with replication and potentially not re-attaching at all if there are db errors -- so just don't use it unless you intend to move the db to a different server/instance entirely.
0
 
LVL 16

Expert Comment

by:Gerald Connolly
ID: 39936449
Backup anyway
0
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 

Author Comment

by:jpmoreau
ID: 39937712
How to ALTER the settings when the DB is offline?
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39937744
I think you can use the alter even while the database is offline:
    http://technet.microsoft.com/en-us/magazine/gg452698.aspx
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 39937878
You alter before the database goes offline.  Indeed, you want to check it carefully before you take the db offline, and make sure that it is correct, just to avoid problems when you put it back online.

ALTER DATABASE <db_name>
MODIFY FILE ( NAME = <logical_file_name>, FILENAME = '<full_path_to_new_file>\filename.ext' )

ALTER DATABASE <db_name>
MODIFY FILE ( NAME = <logical_file_name2>, FILENAME = '<full_path_to_new_file>\filename2.ext' )

--...


Then run this before taking it offline:

EXEC db_name.sys.sp_helpfile

to make sure all the new file locations are correct before you take it offline, copy the files, bring it back online.

Note that if you copy the files to the new location, you don't have to take a separate backup first, since the original files can be brought back online if you hit any error with the new file locations.
0
 

Author Closing Comment

by:jpmoreau
ID: 39937920
Thank you. The best way I found is to backup and restore to another place.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now