How to move transaction log for database using sqlcmd / command line?

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

+5
source share
1 answer

You can do this with the ALTER DATABASE command , but you still have to move the file manually. ALTER commands are as follows:

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

For more information, see the SqlServer Central article and the full script for performing the move.

+6

All Articles