Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving database to new path in the same server SQL 2005

Status
Not open for further replies.

Ronel17

Technical User
Dec 31, 2004
60
US
Hi All,
I'm new to SQL. In a fresh insatllation I'm trying to move the database to an another drive and the logs to a separate drive. Help please.
Ron
 
Are these system databases or user databases?

To move a user database you have to detach it. Right click on the db and select tasks-> detach.
Then copy the .mdf and .ldf files to the location you want.
Go back to SSMS right click on Databases and select attach.
Enter the path to your .mdf and .ldf files.

If you need to move your system databases post back and I'll give you instructions.

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Since this is a fresh install. I uninstall SQL2005.
My new question is how do I install SQL 2005 and choose where to put my Data (E) log (F) Tempdb (F).
Hope you can help.
Thanks

on
 
You can't do that on the install. You can select the advanced option on the third or fourth screen to select your install path. But after the install you would have to move your databases.



- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
No Problem
If you have any questions on how to move databases after you install see this thread.

thread962-1345781

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
use master
go
Alter database tempdb modify file (name = tempdev, filename = '
F:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\tempdb.mdf')
go
Alter database tempdb modify file (name = templog, filename = '
F:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\templog.ldf')
Go



Will that be ok, to move my temp db from a drive G to a drive F?

Thanks
 
Yes,
You will need to restart the services for the move to take effect.

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
This what I get:


Msg 5121, Level 16, State 1, Line 1
The path specified by "
E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\tempdb.mdf" is not in a valid directory.
Msg 5121, Level 16, State 1, Line 1
The path specified by "
E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\templog.ldf" is not in a valid directory.
 
The folders need to exists before you make the change.

Create the folders
E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\

Then run it again.

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Are there other db's on that drive?
Can SQL see the E: drive?

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Is E & F a MAPPED drive? If so, you can't use them.

BTW- For user databases, once your install is done, right click on the instance in Enterprise Manager, select properties. Go to the Database Settings tab and you can set where you want the data and log files to go when you create a new database.

-SQLBill

Posting advice: FAQ481-4875
 
Hi Paul,
No there is no other db on that drive. Yes I can see the E: drive from SQL.

Ron
 
Hi Bill,
No there not map drive. I'm talking about Syatem database, the tempdb.
Thanks

Ron
 
Ronel,
Are you sure you don't have a type-o somewhere in the path or in you TSQL?

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Paul,
That was the first thing I checked.
Here is the path on the server where I want it:
E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data

Now I have it in :
F:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data

And I use:
use master
go
Alter database tempdb modify file (name = tempdev, filename = '
E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\tempdb.mdf')
go
Alter database tempdb modify file (name = templog, filename = '
E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\templog.ldf')
Go


Thanks

Ron
 
Ron,
That looks correct. So I have a few more questions.
1 Is this server a cluster?
2 Is the E:\ drive a dynamic disk?

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Paul,
1)No it's not a cluster.
2)No

Thanks

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top