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 CPOL
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)

Share

About the Author

Kale Yogesh
Technical Lead
India India
Having 4+ years of professional software development experience in analysis, design, development, testing and implementation of enterprise web applications for automobile, Digital Marketing, Telecommunication domain with good exposure to object-oriented design, software architectures, design patterns, test-driven development and agile practices.
 
Area of Working : Dedicated to Microsoft .NET Technologies
Proficient in: C# , ASP.net, SQL
 
Software Development
 
Database: Microsoft SQL Server,
Development Frameworks: Microsoft .NET 1.1, 2.0, 3.5, 4.0
UI: Windows Forms, ASP.NET Web Forms and ASP.NET MVC3, JQuery
Coding: WinForm , Web Development, XHTML, XML, HTML5, Javascript, WCF
 
Achievements:
First prize in National Level Project competition in Academic
Winner in Dotnet contest by Microsoft
Winner in Dotnet contest by Techgig
Winner in SQL Server Solution contest by Microsoft

Comments and Discussions

 
GeneralI would shrink the log using TRUNCATEONLY but I don't think ... PinmemberKeith.Badeau1-Apr-11 8:03 
GeneralMore detailed: If you do not care about db-changes between y... PinmemberWolle Wagner27-Mar-11 8:18 
GeneralBut if you want to restore the database afterwards, it will ... PinmemberWoutL1-Mar-11 23: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 | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 24 Feb 2011
Article Copyright 2011 by Kale Yogesh
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid