How To Truncate Log File in SQL Server 2005
How To Truncate Log File in SQL Server 2005
Introduction
SQL 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.
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,
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 Remove
button. 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
Balmukund
Balmukund
Microsoft 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
inShare0
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.
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.
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