Truncate Logs for SQL Server 2005


I’m frequently trying to figure this out but never remembering the exact syntax, so here it is! A quick/easy way to truncate logs on a database via script!

* NOTE: I don’t recommend this for production databases unless you tweak it to be good. This is more for dev environments where you don’t really care about transaction logs!

1
2
3
4
5
USE [{DatabaseName}]
GO
DBCC SHRINKFILE({TransactionLogLogicalName}, 1)
BACKUP LOG [{DatabaseName}] WITH TRUNCATE_ONLY
DBCC SHRINKFILE({TransactionLogLogicalName}, 1)

Happy truncations!

-Shane

No Comments

No comments yet.

Comments RSS TrackBack Identifier URI

Leave a comment


Jaxidian Update is proudly powered by WordPress and themed by Mukkamu