use admin GO SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ShrinkLogs]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[ShrinkLogs] GO CREATE PROCEDURE [dbo].[ShrinkLogs] AS /******************************************************************************************************* * admin.dbo.ShrinkLogs * Creator: Bill Wunder * bwunder@yahoo.com * * Date: 3-13-2003 * * Project: utility * * Description: shrinks all logs larger than 100MB for DBs with SIMPLE recovery model to 100MB * * Usage: EXECUTE admin.dbo.ShrinkLogs * Notes: * * Modifications: * Developer Name Date Brief Description * ------------------ -------- ------------------------------------------------------------ * ********************************************************************************************************/ --------------------------------------------- -- declare variables --------------------------------------------- --------------------------------------------- -- create temp tables --------------------------------------------- --------------------------------------------- -- set session --------------------------------------------- SET NOCOUNT ON --------------------------------------------- -- body of stored procedure --------------------------------------------- exec sp_msforeachdb 'If DATABASEPROPERTYEX(''?'', ''Recovery'') = ''SIMPLE'' begin use ? set nocount on declare @SQLStr nvarchar(255) create table #files (name varchar(128), fileid tinyint, filename varchar(128), filegroup varchar(128), size varchar(20), maxsize varchar(20), growth varchar(20), usage varchar(10)) insert #files exec sp_helpfile select @SQLStr = ''DBCC SHRINKFILE('' + cast(min(fileid) as varchar(5)) + '',100)'' from #files where usage = ''log only'' print db_name() exec sp_executesql @SQLStr end' GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO