The following is a script that I use to shrink the transaction logs of my databases. I have written the script for each database and put the scripts in a DTS package to run each day. Hope this helps...
/*************************************************************************************
* Name: ShrinkTransLog.sql
* Date: 6/12/00
* Purpose: To reduce a transaction log to 1 MB
* Source: MSDN Newsgroups from 6/9/00
*
* Note: Before running this script, replace "DATABASE" with the correct database name
* of the transaction log that you want to shrink. Also (very important), be
* aware of the actual .mdf and .ldf names within the database. Some of the
* .mdf files may have a "_data" in their name. Others may not.
* Some of the .ldf files may have a "_log" in their name. Others may not.
* Also realize that, within STEPS 2 and 3, replace drive 'e' with the proper
* drive housing the "mssql7" directory
*
**************************************************************************************/
use master
go
-- Step 1: Detach database
exec sp_detach_db 'DATABASE','true'
go
-- Step 2: Rename current log file
exec xp_cmdshell 'del e:\mssql7\data\*.ldf_sql',no_output
go
exec xp_cmdshell 'ren e:\mssql7\data\"DATABASE_log.ldf" "DATABASE_log.ldf_sql"'
go
print "
print '*****************************************************************'
print '* Log file has been renamed with a *.ldf_sql extension. *'
print '*****************************************************************'
print "
-- Step 3: Reattach database and create new log file with size of 1 MB
exec sp_attach_db @dbname = N'DATABASE',
@filename1 = N'e:\mssql7\data\DATABASE_Data.mdf'
go
-- Step 4: Display transaction log info
DBCC SQLPERF (LOGSPACE)
/*
* Note: If all goes well, you way want to delete the *ldf_sql file to free up space.
* Also, restrict the file growth of the transaction log to 2 MB (or whatever you want).
* Do this in the Enterprise Manager, right-click the database, select "Properties",
* and click on the "Transaction Log" tab.
*/