devxlogo

Moving Transaction Logs to a Different Drive

Moving Transaction Logs to a Different Drive

You can move a transaction log using SQL Server stored procedures. Simply detach the database, move the log file, then reattach the database. For example, to move the pubs database from drive C to drive D, use the following sp_detach_db command to detach the database:

EXEC sp_detach_db 'pubs'

Next, copy the pubs.mdf and pubs_log.ldf files to the destination drive. The following example shows how to copy these two files to the d:mssql7data directory:

copy c:mssql7datapubs.mdf d:mssql7datacopyc:mssql7datapubs_log.ldf d:mssql7data

Finally, after you copy the files, you can use sp_detach_db to reattach the data to SQL Server:

EXEC sp_attach_db 'pubs', 'd:mssql7datapubs.mdf','d:mssql7datapubs_log.ldf'

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist