SQL 2008 shrink log file size with no_log alternative

Microsoft SQL Server 2008 no longer allows you to truncate the transaction log using the no_log syntax. Essentially, Microsoft decided (arguably correctly) that too many people were “abusing” the statement and doing harm to themselves.

But when your logfiles have grown too large because you are not backing them up often enough, you can use the following code to accomplish the same results as “with no_log”. If you don’t understand why Microsoft deprecated the “with no_log”, you should probably do more digging before you use anything posted here.

The Code

USE MASTER
GO
ALTER DATABASE database_name SET RECOVERY SIMPLE
GO
USE database_name
GO
DBCC SHRINKFILE (database_name_log, 1)
GO
ALTER DATABASE database_name SET RECOVERY FULL
GO

SQL 2008 returns a table of shrinkfile related results plus the following confirmation:

(1 row(s) affected)
DBCC execution completed. If DBCC printed error 
messages, contact your system administrator.

One Comment

Comments are closed.