Click here to Skip to main content
12,634,690 members (24,095 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

24.8K views
13 bookmarked
Posted

How to Shrink SQL Server database log files?

, 5 Jan 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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?[^]

License

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

Share

About the Author

thatraja
Web Developer
India India
Retired from Q/A section & Technical forums since 2014

More coming soon....

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 1 Log files do not need to be truncate... Pin
HLogic4-Jan-11 15:20
memberHLogic4-Jan-11 15:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161208.2 | Last Updated 5 Jan 2011
Article Copyright 2010 by thatraja
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid