Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I move the Transaction Log for a database using sqlcmd/command line?

Tags:

sql

sql-server

I need to move the transaction log for a database I have just created using aspnet_regsql.
Is it possible to move the transaction log using sqlcmd or any other command line tool?

like image 758
SharePoint Newbie Avatar asked Oct 15 '09 11:10

SharePoint Newbie


1 Answers

You can do so with the ALTER DATABASE command, but you still have to move the file manually. The ALTER commands look like this:

ALTER DATABASE YourDb SET OFFLINE;

ALTER DATABASE YourDb
MODIFY FILE (Name = YourDb_Log,
    Filename = 'g:\NewDir\YourDb.ldf')

<At this point, move the file in the filesystem>

ALTER DATABASE YourDb SET ONLINE;

RECONFIGURE

See this SqlServer Central article for more information, and a complete script to execute the move.

like image 138
Andomar Avatar answered Nov 06 '22 01:11

Andomar