[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

How to move LDF file to another drive for already created database?

I have a 23GB database MDF and 1GB database LDF located in E:\SQLServer.

I understand that if I shift my LDF file to another hard disk, eg. D:, the performance might be slightly faster.

I tried to detach the database and delete the LDF file. When I reattach the MDF, SQL2000 will re-create the LDF file back in E:\SQLServer, but I wish to move the LDF file to D:\, which is another hard disk. How do I do this?

Thank you.
0
cq27
Asked:
cq27
1 Solution
 
mcv22Commented:

ALTER DATABASE DatabaseName MODIFY FILE (NAME = Database_Log, FILENAME = 'D:\SQLServer\Database_log.ldf')

Open in new window

0
 
Aaron ShiloCommented:
hi

why did you delete the LDF?

use master
GO
   sp_detach_db 'YOURDATABASE'
   go
   sp_attach_db 'YOURDB','E:\Sqldata\DATAFILE.mdf','D:\Sqldata\LOGFILE.ldf'
   go

0
 
cq27Author Commented:
Thanks for your solution. It is the easiest to understand. I tried to follow others' instructions but no one seem to be as clear as yours.

I have tried it on a test database and it works. Thank you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now