Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Movins SQL DB

Posted on 2014-03-17
7
Medium Priority
?
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 41

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 70

Expert Comment

by:Scott Pletcher
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 17

Expert Comment

by:Gerald Connolly
ID: 39936449
Backup anyway
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

Accepted Solution

by:
Kyle Abrahams earned 2000 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 70

Expert Comment

by:Scott Pletcher
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

609 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