SQL 2008 Truncate log files for all databases

First, let me qualify this post. This is not my code. I modified the code to fit my needs. The original code and article are here.

My modification simply allows the script to bypass any databases that are offline. We occasionally will take a database offline and leave it that way for a few weeks. By simply adding the statement “AND DATABASEPROPERTYEX(name, ‘status’) = ‘ONLINE'” to the original code, I was able to accomplish this, which made the next step even easier, automating this script to run once a week.

All of this came about because we were unable to get this to run reliably as part of a Maintenance Plan. By implementing this script as a SQL Agent Job, separate from our maintenance plans, we were able to get control of unwieldy log files.

Many of you may find this useful, especially on a server where databases are being created and deleted on an almost daily basis.

for an explanation of the base code, without my modifications, read this.

3 Replies to “SQL 2008 Truncate log files for all databases”

  1. Well I truly liked reading it. This article offered by you is very useful for correct planning.

  2. Your post, XpertNotes » SQL 2008 Truncate log files for all databases, is really well written and insightful. Glad I found your website, warm regards!