of 18/18
How to Truncate Log File in SQL Server 2005 By [email protected] | 9 Jun 2006 WinXPWin2003SQL2005C#SQLWindows.NETSQL-ServerVisual-StudioArchitect , + How to truncate log file in SQL Server 2005

How to Truncate Log File in SQL Server 2005

  • View

  • Download

Embed Size (px)

Text of How to Truncate Log File in SQL Server 2005

How to Truncate Log File in SQL Server 2005By [email protected] | 9 Jun 2006WinXPWin2003SQL2005C#SQLWindows.NETSQL-ServerVisual-StudioArchitect,


How to truncate log file in SQL Server 2005

IntroductionSQL Server 2005 is quite different from SQL Server 2000. To truncate log file is one thing which is different from SQL Server 2000. In SQL Server 2000, you just use Shrink to whatever file size you like. In SQL Server 2005, sometimes I cannot shrink the log file at all. Here I want to describe some tricks to truncate log file for a database in SQL Server 2005. The work environment is Microsoft SQL Server Management Studio.

I. Shrink the Log File Size at the Right TimeI found out this trick: Immediately after I use the SSIS package or Import the data to the database (highlight the database->Tasks->Import data ), or Export the data from the database (highlight the database->Tasks->Export data ), I can shrink the log file to the desired size, for example, 1MB. That is, highlight the database->Tasks->Shrink->Files , set the file size, say, 1MB. Then, click OK and you are done.

II. Eliminate the Log File CompletelySometimes, we just do not need the big log file. For example, I have a 40GB log file. I am sure I do not need this log file and want to get rid of it completely to free up the hard drive space. The logic is:

1. Detach the database

2. Rename the log file 3. Attach the database without the log file 4. Delete the log file Lets say, the database name is testDev. In the SQL Server Management Studio,

1. Highlight the database-> Tasks->Detach..-> Click OK

2. Go to log file folder -> rename the testDev_log.ldf to be like testDev_log-aa.ldf 3. Highlight Databases->Attach-> Click Add -> add the database testDev, highlight the log file and click the Removebutton. This means you only attach testDev.mdf

4. After this is done, you can verify the contents of the attached database and then delete the log file

Hi All,

Open SQL Management Studio Select Perticular DB, Right Click DB--->Task--->Bring Task Offline. Copy the Transaction Log into L Drive, Make sure to change in the SQL Databse Properties ...>Files....> Transaction Log Location. Then Bring the DB Online. I hope It will help you Regards Ganga o o o o Reply Quote Friday, May 27, 2011 7:47 AM

Proposed As Answer byGangaiyan Friday, May 27, 2011 6:56 AM


BalmukundMicrosoft MSFT 17,895 Recent Achievements 15 8 1 Thread Mover II Proposed Answerer I Blog Party Starter Balmukund's threads View Profile

Microsoft (MSFT)17,895

1 Sign In to Vote Another method without detaching: 1. 2. 3. 3. Run ALTER DATABASE command and change location of ldf file Take database offline Move the physical file from old location to new location. Bring database online

Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other user's find a solution quicker -------------------------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no rights. -------------------------------------------------------------------------------My Blog: http://blogs.msdn.com/blakhani Team Blog: http://blogs.msdn.com/sqlserverfaq

Delete, Shrink, Eliminate Transaction Log .LDF FilePosted on April 1, 2011 by hoanhuynh


In some case, the Microsoft SQL Server Database Transaction Log (.LDF) file becomes very big even ton of Gigabytes. Its wasting lot of disk space and causing some problems if you want to backup and restore the database. To face with this issue, in this tutorial, you can apply either of following methods. Im on Microsoft SQL Server 2008 but it also be applied for Microsoft SQL Server 2005.

1. Shrink the transaction log (.ldf) fileBy using this method, you can shrink the log to the desired size, ex: 1MB + Right-click on the database you want to shrink => Tasks => Shrink => Files

Microsoft SQL Server 2008 Shrink + On Shrink File box, select Log on File type drop down list and select Reorganize pages before releasing unused space then set size for the log file, ex: 1 MB as picture below:

Microsoft SQL Server 2008 Shrink Set Size Log File + Click OK and youre done. The good point of this method is you can shrink at the right time but sometime, it doesnt work especially with Microsoft SQL Server 2005. Lets try the second method below in case its does not work.

2. Completely delete the log fileThe main idea of this method is it will delete the big log file and create a new log file with the minimum size. Follow steps below: 1. Detach the database Right-click on the database => Tasks => Detach

Microsoft SQL Server 2008 Detach 2. Delete the big log file This step will completely erase it from your hard drive. However, from my suggestion you should back up the log file somewhere, ex: rename it from the file location (my case is: C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA)

Microsoft SQL Server 2008 Data Folder 3. Attach the database again As we deleted the log file, so we do attach the database without the log file. Dont worry, SQL Server will create a new log file for you which will be of the minimum size. Thats perfect! + Right-click Databases => Attach

Microsoft SQL Server 2008 Attach + On Attach Database box, click Add

Microsoft SQL Server 2008 Attach Add + Browser to the database (.mdf) file then click OK

Microsoft SQL Server 2008 Browser MDF + Select the log (.ldf) file then click Remove

Microsoft SQL Server 2008 Attach Remove Log

Read more: http://4rapiddev.com/sql-server/delete-shrink-eliminate-transaction-log-ldf-file/#ixzz1Ybp7Nyw8