65.9K
CodeProject is changing. Read more.
Home

How to Shrink SQL Server database log files?

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.23/5 (9 votes)

Jan 19, 2010

CPOL
viewsIcon

41041

How to Shrink SQL Server database log files?

Database Logs should be truncated whenever you perform a full backup of the database. You can also manually truncate them as follows.

Code

DECLARE @strDatabaseName nvarchar(255)
SET @strDatabaseName = 'YourDatabaseName' 
BACKUP LOG @strDatabaseName WITH TRUNCATE_ONLY 
DBCC SHRINKDATABASE (@strDatabaseName, 0)--Parameters are Database Name & Target %
It was tested in SQL Server 2005 & it's working. It was also tested in SQL 2008 & it's working too.

For Your Information

Why won't my transaction log shrink?[^]