MS SQL

MS SQL

--select * from [master].[sys].[databases]
 -- ('master','tempdb','model','msdb')
 -- : DBCC SHRINKFILE ('+@name+ '_log, X) where X is the target size in MB.
 -- FULL SIMPLE 

declare @name nvarchar(512)
 declare @cmd nvarchar(512)
 DECLARE @Cursor CURSOR
 SET @Cursor = CURSOR FOR
 select name from [master].[sys].[databases]
 where not name in ('master','tempdb','model','msdb')
 
OPEN @Cursor
 FETCH NEXT FROM @Cursor INTO @name
 
WHILE (@@FETCH_STATUS = 0)
 BEGIN
 print @name
 set @cmd =
 'USE ['+@name+']
 ALTER DATABASE '+@name+' SET RECOVERY SIMPLE
 DBCC SHRINKFILE (N'''+@name+ '_log'', 0, TRUNCATEONLY)
 ALTER DATABASE '+@name+' SET RECOVERY FULL'
 
print @cmd
 exec (@cmd)
 
FETCH NEXT FROM @Cursor INTO @name
 end

.. USE [+@name+]
ALTER DATABASE +@name+ SET RECOVERY SIMPLE
DBCC SHRINKFILE (N+@name+ _log, 0, TRUNCATEONLY)
 ALTER DATABASE '+@name+' SET RECOVERY FULL

, master,tempdb,model,msdb
!: FULL SIMPLE !!

<