Solved

Move databse files

Posted on 2006-11-08
6
206 Views
Last Modified: 2008-02-01
Hi,
Is there a way appart from the restore process to move the database files in different drives than they were originally?
for example from X: to Y:

Cheers,

R.
0
Comment
Question by:racineconde
[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
  • 4
6 Comments
 
LVL 28

Expert Comment

by:imran_fast
ID: 17897782
CHECK FOR SP_DETACH AND SP_ATTCH
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 17897785
2 methods:
* backup the database, and during a restore, you can choose new locations for all the files individually
* detach the database, move the files, and use the procedure sp_attach_db to attach the db back to the server with the files in the new locations
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 17897795
use sp_detach_db to detach the db files
copy the files(log and mdf) to other location on the server and then use sp_attach db to attach the file.
The detached files remain and can be reattached using sp_attach_db or sp_attach_single_file_db. The files can also be moved to another server and attached.


EXEC sp_detach_db 'pubs'

This example attaches two files from pubs to the current server.

EXEC sp_attach_db @dbname = N'pubs',
   @filename1 = N'y:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf',
   @filename2 = N'y:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'

0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 

Author Comment

by:racineconde
ID: 17897939
There's another way by using the ALTER DATABASE Statement. I've got an error when I try to run it. Is someone has an idea of WHY

***********************
USE Master
GO
ALTER DATABASE myDB
MODIFY FILE (NAME = myDB_Data, FILENAME = 'D:\myDB.mdf')
GO
ALTER DATABASE myDB
MODIFY FILE (NAME = myDB_Log, FILENAME = N'H:\myDB_log.mdf')
GO

*******************
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 17898039
what is the error you are getting.
0
 
LVL 28

Assisted Solution

by:imran_fast
imran_fast earned 100 total points
ID: 17898102
this can only be done to tempdb check alter database command in books online there is a note may be you missed that

Note  This example is applicable to tempdb only. To move user databases, use sp_detach_db and sp_attach_db. For more information, see Attaching and Detaching a Database.
0

Featured Post

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

691 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