SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to empty the transaction log file?

If for some reason the transaction log became too large, like 20GB for a 3GB database, or contains leftover from various processes such as replication, you can empty it quickly the following ways.

A. Exit users, Backup database

B. Change database to SIMPLE recovery model

C. In SSMS Object Explorer Perform Shrink Database Files for log

You can also use script:

USE [AdventureWorks2008]

GO

DBCC SHRINKFILE (N'AdventureWorks2008_Log' , 0, TRUNCATEONLY)

GO

The following method works even if dbcc shrinkdatabase or dbcc shrinkfile fails :

1. Exit users

2. Check for open transactions with dbcc opentran - resolve if any

3. Backup the database (full backup) with verification

4. Detach the database in Object Explorer

5. Rename the transaction log file (discard later e.g. in a week)

6. Attach the database in OE (remove "not found" .ldf file)

7. Perform dbcc checkdb

8. Backup database with verification

9. Open database for users

An empty log file will be created upon attach. Database should be fully operational.

Related articles:

How to: Shrink a Database (SQL Server Management Studio)

Recover from a full transaction log in a SQL Server database

http://sqlusa.com/bestpractices2005/shrinklog/

 

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.