Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL
Expertise: Beginner
Jun 25, 2003



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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:\mssql7\data directory:

copy c:\mssql7\data\pubs.mdf d:\mssql7\datacopy
c:\mssql7\data\pubs_log.ldf d:\mssql7\data
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:\mssql7\data\pubs.mdf',

Devington B.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date