Monday, February 12, 2007

SQL Server: How to shrink transaction logs

This is just a sequence that I forget sometimes-- every now and then I get a transaction log that is bigger than I want it to be. This shrinks it pretty well. One thing to be cautious about: make a full backup of the database after you do this.




use MyDatabase
go
checkpoint
go
backup log MyDatabase with truncate_only
go
dbcc shrinkdatabase(MyDatabase)
go
dbcc shrinkfile(MyDatabase_Log)


Now, make a complete backup of the database.




No comments:

Post a Comment

I moderate comments blog posts over 14 days old. This keeps a lot of spam away. I generally am all right about moderating. Thanks for understanding.