Click here to Skip to main content
Click here to Skip to main content

SHRINKFILE and TRUNCATE Log File in SQL Server 2008

, 23 Feb 2011
Rate this:
Please Sign up or sign in to vote.
SHRINKFILE and TRUNCATE Log File in SQL Server 2008
When we create a new database inside the SQL Server, it is typical that SQL Server creates two physical files in the Operating System: one with .MDF Extension, and another with .LDF Extension.
* .MDF is called as Primary Data File.
* .LDF is called as Transactional Log file.
 
Sometimes, it looks impossible to shrink the Truncated Log file. The following code always shrinks the Truncated Log File to minimum size possible.
USE DatabaseName
GO
ALTER DATABASE [DBName] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE([DBName_log], 1)
ALTER DATABASE [DBName] SET RECOVERY FULL WITH NO_WAIT
GO

License

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

About the Author

YogiKale
Software Developer
India India
No Biography provided

Comments and Discussions

 
GeneralI would shrink the log using TRUNCATEONLY but I don't think ... PinmemberKeith.Badeau1-Apr-11 7:03 
GeneralMore detailed: If you do not care about db-changes between y... PinmemberWolle Wagner27-Mar-11 7:18 
GeneralBut if you want to restore the database afterwards, it will ... PinmemberWoutL1-Mar-11 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.8.140721.1 | Last Updated 24 Feb 2011
Article Copyright 2011 by YogiKale
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid