Move Log File to another drive

  • Hello everyone, How can I move my log file to another drive? Thanks.

  • Hi,

    You can detach your database, and move your log file to new location. While attaching the database back again, you need to specify the new location of the log file, and that should be it.

    Thanks,

    Chandra

  • Thanks a bunch for the link, it is very helpful!

  • Check that you have a single mdf and a single ldf file. If you have multiple log files you may encounter difficulties with the re-attachment. (Worst case is you loose the lot)!

    -- Change current DB to Master

    USE Master

    GO

    -- Detach DB

    EXECUTE sp_detach_db 'MyDatabase', 'True'

    -- I Drop the file here but you could just move it ?

    EXECUTE master..xp_cmdshell "del d:\MSSQL7\data\MyDatabase_Log.LDF"

    -- Reatach the DB

    --NOTE: you may need to use subseqent @filename if you want your original log file re-attached

    EXECUTE sp_attach_db @dbname = N'MailingUtilities', @filename1 = N'd:\MSSQL7\data\MyDatabase_Data.MDF'

    Regards

    Andy P


    Andy P

  • Just a quick point following on from Andy. By deleteing the log and then running sp_attach_db and only supplying a data file to be attatched, a new log file will be created in the same directory as the log file.! And will be only 1Mb in size.

    Clive Strong

    clivestrong@btinternet.com

  • I posted a seperate item on this because I got some strange feedback from the sp_helpdb after I moved the log file and ran sp_attach_db without the log file specified. The Log file path in sp_helpdb contained an extra "backslash" between the folder and the file names. For example: d:\MSSQL7\Data\\MyDB_Log.ldf.

    Runs fine, but won't this cause problem later?

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply