?
Solved

Move databse files

Posted on 2006-11-08
6
Medium Priority
?
210 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 750 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

764 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