Solved

Move databse files

Posted on 2006-11-08
6
199 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
  • 4
6 Comments
 
LVL 28

Expert Comment

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

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Optimizing a query 3 34
SQL Select Statement 2 22
SQL Server - Slabs 9 38
recover sqlserver db 8 55
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 …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

895 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

14 Experts available now in Live!

Get 1:1 Help Now