Register   |  Login
You are hereArticles
 Article Details
Reduce or truncate the size of the SQL Server log file

We sometimes see that log file (.ldf) is bigger than data file (.mdf). There are times we run out of disk space because of the growing log file.

 Let’s find out how to shrink or truncate the growing log file by using DBCC (Database Console Commands) commands.

Now we are interested in shrinking the log file. We need to run DBCC command against the log file. But to run against, we first need to know the log file name.

SELECT name FROM Sysfiles

The above query will return the database and log file name. Now we got the log file name.

Let’s run the DBCC command now. The following command shrinks the log file.

DBCC SHRINKFILE('SampleDB_Log', 2)

Here 'SampleDB_Log' is the log file and 2 is target file size in MB.

 

Even after executing the command, if you have not got the expected size of the log file, we might have to truncate the logs. The following command would truncate the transaction log

BACKUP LOG SampleDB WITH TRUNCATE_ONLY

Here SampleDB is the database name.

 

Now again run the shrink file command

DBCC SHRINKFILE('SampleDB_Log', 2)

Now you will be seeing the target size achieved. That’s it.

Happy Programming!!!


Written By: Kumaravel
Date Posted: 1/20/2009
Number of Views: 809


Comments
lu juan Says:
4/5/2011 5:24:45 PM

My favorite part of the suite is Microsoft Office 2010 . You can use it like a fancy clipboard, but Office 2010 is much more powerful and useful.So, I'm forced to pay for an upgrade to Microsoft Office that I did not want.For the price, you can't go wrong with Outlook 2010 Home & Student. And, I may or may not be able to use the Product Key on the package I purchased to activate only Word, Excel, Microsoft outlook 2010PowerPoint and OneNote, the programs I thought I was buying. The only answer was to go to MS Office, or have everyone else in the world switch to Office 2007 .The instructions on the Microsoft website for activating Office imply that the full Microsoft Office 2007 Professional suite is the only version eligible for proper licensing.


You must be logged in to submit a comment.

Return