declare @dbname sysname declare @sql nvarchar(1000) declare db_cursor cursor for select name from master.dbo.sysdatabases where name not in ('tempdb', 'model', 'msdb', 'master') open db_cursor fetch next from db_cursor into @dbname while @@fetch_status = 0 begin print @dbname select @sql = ' ALTER DATABASE [' + @dbname + '] SET RECOVERY SIMPLE DBCC SHRINKDATABASE ([' + @dbname + ']) ALTER DATABASE [' + @dbname + '] SET RECOVERY FULL' exec sp_executesql @sql fetch next from db_cursor into @dbname end close db_cursor deallocate db_cursor