Solved

Movins SQL DB

Posted on 2014-03-17
7
152 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 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: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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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: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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

688 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