How to Truncate Log File in SQL Server 2005

By | 9 Jun 2006


How to truncate log file in SQL Server 2005

-> Click OK . we just do not need the big log file. Delete the log file Let’s say. or Export the data from the database (highlight the database->Tasks->Export data …). Detach the database 2. Then. I can shrink the log file to the desired size. In SQL Server 2005. 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. 1. Highlight the database-> Tasks->Detach. you just use Shrink to whatever file size you like. 1MB. That is.. In SQL Server 2000. Attach the database without the log file 4. Eliminate the Log File Completely Sometimes. The work environment is Microsoft SQL Server Management Studio. for example. 1MB.Introduction SQL Server 2005 is quite different from SQL Server 2000. set the file size. For example. The logic is: 1. II. In the SQL Server Management Studio. I have a 40GB log file. Shrink the Log File Size at the Right Time I found out this trick: Immediately after I use the SSIS package or Import the data to the database (highlight the database->Tasks->Import data …). Here I want to describe some tricks to truncate log file for a database in SQL Server 2005. click OK and you are done. say. highlight the database->Tasks->Shrink->Files . To truncate log file is one thing which is different from SQL Server 2000. Rename the log file 3. sometimes I cannot shrink the log file at all. I. the database name is testDev.

2011 7:47 AM Proposed As Answer byGangaiyan Friday. I hope It will help you Regards Ganga o o o o • Reply Quote Friday. This means you only attach testDev.. May 27. Highlight Databases->Attach…-> Click Add -> add the database testDev. you can verify the contents of the attached database and then delete the log file • Hi All.2.ldf to be like testDev_log-aa... Open SQL Management Studio Select Perticular DB. Make sure to change in the SQL Databse Properties .> Transaction Log Location.>Files. Copy the Transaction Log into L Drive.ldf 3. After this is done.mdf 4. May 27. Right Click DB--->Task--->Bring Task Offline. 2011 6:56 AM . highlight the log file and click the ‘Remove’ button... Go to log file folder -> rename the testDev_log. Then Bring the DB Online.

2.Balmukund Balmukund Microsoft MSFT 17. 3.895 1 Sign In to Vote Another method without detaching: 1. 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 . 3.895 Recent Achievements 15 8 1 Thread Mover II Proposed Answerer I Blog Party Starter Balmukund's threads View Profile Microsoft (MSFT) 17.

com/sqlserverfaq Delete.LDF File Posted on April 1. and confers no Team Blog: http://blogs. Shrink. 2011 by hoanhuynh inShare0 . -------------------------------------------------------------------------------My Blog: http://blogs. vote for it as helpful to help other user's find a solution quicker -------------------------------------------------------------------------------This posting is provided "AS IS" with no warranties.Balmukund Lakhani | Please mark solved if I've answered your question.msdn.msdn. Eliminate Transaction Log .

It’s wasting lot of disk space and causing some problems if you want to backup and restore the database. I’m on Microsoft SQL Server 2008 but it also be applied for Microsoft SQL Server 2005. in this tutorial. Shrink the transaction log (. the Microsoft SQL Server Database Transaction Log (.ldf) file By using this method.LDF) file becomes very big even ton of Gigabytes. you can shrink the log to the desired size. you can apply either of following methods.In some case. 1. To face with this issue. ex: 1MB + Right-click on the database you want to shrink => Tasks => Shrink => Files .

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 + On Shrink File box.


The good point of this method is you can shrink at the right time but sometime. Completely delete the log file The main idea of this method is it will delete the big log file and create a new log file with the minimum size. Detach the database Right-click on the database => Tasks => Detach… . 2. Follow steps below: 1. Let’s try the second method below in case it’s does not work.Microsoft SQL Server 2008 Shrink Set Size Log File + Click OK and you’re done. it doesn’t work especially with Microsoft SQL Server 2005.

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

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

Microsoft SQL Server 2008 Attach + On Attach Database box. click Add… .


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


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


Microsoft SQL Server 2008 Attach Remove Log

Sign up to vote on this title
UsefulNot useful