Click here to Skip to main content
13,048,406 members (125,406 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


13 bookmarked
Posted 19 Jan 2010

How to Shrink SQL Server database log files?

, 5 Jan 2011
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.


DECLARE @strDatabaseName nvarchar(255)
SET @strDatabaseName = 'YourDatabaseName' 
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?[^]


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


About the Author

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 Not a good advice Pin
msmits10-Jan-11 2:08
membermsmits10-Jan-11 2:08 
GeneralReason for my vote of 4 Good Tip....... Pin
Vivek Johari6-Jan-11 16:30
memberVivek Johari6-Jan-11 16:30 
General@HLogic: Hi it's just a Tip/Trick so I just entered script o... Pin
thatraja4-Jan-11 14:52
mvpthatraja4-Jan-11 14:52 
GeneralReason for my vote of 1 Log files do not need to be truncate... Pin
HLogic4-Jan-11 14:20
memberHLogic4-Jan-11 14:20 
GeneralReason for my vote of 5 ok log Pin
ronal74-Jan-11 9:55
memberronal74-Jan-11 9:55 
GeneralReason for my vote of 5 its good tip Pin
Pranay Rana2-Jan-11 23:32
memberPranay Rana2-Jan-11 23:32 
GeneralYou shouldn't shrink whenever you do a full backup... Pin
msmits10-Jan-11 2:06
membermsmits10-Jan-11 2:06 
...unless your database is not growing anyways and you need the space.

One of the most costly database actions is shrinking/growing a data/log file.
Therefore you want to prevent this from happening automatically - especially on large production databases.

AutoShrink is therefore generally NOT a good option - you want your database to behave in a predictable manner.

The method most DBAs will recommend is to size your data/log files manually to a size that will stay constant, and then monitor the size and readjust when necessary.

Last, all depends on context - there is no one-size-fits-all solution.
GeneralRe: You shouldn't shrink whenever you do a full backup... Pin
thatraja10-Jan-11 4:20
mvpthatraja10-Jan-11 4:20 
GeneralWelcome Pin
thatraja1-Feb-10 21:44
memberthatraja1-Feb-10 21:44 

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.

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