DECLARE dbNames_cursor CURSOR
--
-- Run this script routinely to control the growth of LDF log files.
--
FOR
SELECT NAME FROM dbo.sysdatabases where not name in ('master', 'model', 'msdb', 'tempdb')
OPEN dbNames_cursor
DECLARE @dbName nvarchar(50)
FETCH NEXT FROM dbNames_cursor INTO @dbName
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
declare @logName nvarchar(50)
exec(' use [' + @dbName + '] ' + 'backup log [' + @dbName + '] with truncate_only')
set @logName = @dbName + '_log'
exec(' use [' + @dbName + '] ' + 'declare @logName nvarchar(50) select @logName = name from sysfiles where fileid = 2 set @logName = rtrim(@logName) dbcc shrinkfile (@logName)')
dbcc Shrinkdatabase (@dbName, 0)
END
FETCH NEXT FROM dbNames_cursor INTO @dbName
END
CLOSE dbNames_cursor
DEALLOCATE dbNames_cursor
-- Script by Shawn Camner, CCCI
|