--sql server 2005
use SampleDB
GO
DECLARE @DBName NVARCHAR(100)
SET @DBName = DB_NAME()
EXEC('BACKUP LOG [' + @DBName + '] WITH TRUNCATE_ONLY')
GO
SELECT [id]=ROW_NUMBER() OVER (ORDER BY [file_id]), [name]
INTO #log_file_list
FROM sys.database_files
WHERE [type] = 1 --log file
DECLARE @ID INT, @LogFile NVARCHAR(1000)
WHILE EXISTS(SELECT * FROM #log_file_list)
BEGIN
SELECT TOP 1 @ID = [id], @LogFile = [name]
FROM #log_file_list
SELECT log_file = @LogFile, size_before_shrink=[size]
FROM sys.database_files WHERE [name] = @LogFile
DBCC SHRINKFILE(@LogFile, TRUNCATEONLY)
SELECT log_file=@LogFile, size_after_shrink=[size]
FROM sys.database_files WHERE [name] = @LogFile
DELETE FROM #log_file_list WHERE [id] = @ID
END
DROP TABLE #log_file_list