>>/* >>This script chages the DB recevery type to SIMPLE, and >>can change it back to FULL if the lines are not commented out. >>In the mean time, it shrinks the log file size, which is >>the goal of this script. >> >>Written by Rollin Burr >>*/ >> >>SET NOCOUNT ON >> >>DECLARE @DBName VARCHAR (128), >> @LogFile VARCHAR (255), >> @ExeString VARCHAR(512) >> >>DECLARE cDBs CURSOR FOR >>SELECT [name] >>FROM master.dbo.sysdatabases >>WHERE [name] NOT IN ('master', 'tempdb', 'model', 'msdb') >>OPEN cDBs >>FETCH NEXT FROM cDBs INTO @DBName >>WHILE @@fetch_status = 0 >>BEGIN >> SET @ExeString = 'USE ' + QUOTENAME(@DBName) + ';' >> EXEC (@ExeString) >> >> SET @LogFile = ( >> SELECT dbo.sysaltfiles.name >> FROM master.dbo.sysdatabases INNER JOIN dbo.sysaltfiles >> ON master.dbo.sysdatabases.dbid = dbo.sysaltfiles.dbid >> WHERE (master.dbo.sysaltfiles.fileid = 1) AND (master.dbo.sysdatabases.name = @DBName) >> ) >> >> SET @ExeString = 'USE ' + QUOTENAME(@DBName) + ';' >> EXEC (@ExeString) >> >> -- Truncate the log by changing the database recovery model to SIMPLE. >> SET @ExeString = 'ALTER DATABASE ' + QUOTENAME(@DBName) + 'SET RECOVERY SIMPLE' >> EXEC (@ExeString) >> >> -- Shrink the truncated log file to 1 MB. >> SET @ExeString = 'DBCC SHRINKFILE (' + QUOTENAME(@LogFile) + ', 1)' >> EXEC (@ExeString) >> >> -- Comment this in if you want to return the DBs to FULL. >> --SET @ExeString = 'ALTER DATABASE ' + QUOTENAME(@DBName) + 'SET RECOVERY FULL' >> --EXEC (@ExeString) >> >> FETCH NEXT FROM cDBs INTO @DBName >>END >>CLOSE cDBs >>DEALLOCATE cDBs >> >>>>