Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database

How to Shrink SQL Server database log files?

4.23/5 (9 votes)
5 Jan 2011CPOL 41K  
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


SQL
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?[^]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)