Truncate Logs for SQL Server 2008
I had previously posted how to Truncate Logs for SQL Server 2005. Unfortunately, this method does not work in SQL Server 2008. The reason is because the “WITH TRUNCATE_ONLY” command is no longer in SQL 2008. Assuming you run in full recovery mode, the new script to do this is:
1 2 3 4 5 6 7 8 | USE [{DatabaseName}] GO ALTER DATABASE [{DatabaseName}] SET RECOVERY SIMPLE GO DBCC SHRINKFILE({TransactionLogLogicalName}) GO ALTER DATABASE [{DatabaseName}] SET RECOVERY FULL GO |
Simply setting the database mode into simple recovery mode performs the actual truncation but the file is not shrunk by that. DBCC SHRINKFILE will take care of that second step. And don’t forget to put it back into full recovery mode at the end!!
-Shane