Use the cursor compressed database Log Files

nvarchar @databasename DECLARE (100)
- the cursor definition and assignment of the Online acquired all the Name Database
DECLARE getDataBaseCursor Cursor name for SELECT from master.sys.databases state_desc = WHERE 'Online'
- must be opened prior to using the cursor, the cursor is opened
open getDataBaseCursor
- using data acquired fetcth statement, a statement can be a FETCH records into the variables specified in each DB Shrink achieve the
FETCH from getDataBaseCursor Next iNTO @databasename
the while FETCH_STATUS @@ = 0
the begin
 DECLARE @RecoveryModel nvarchar ( 20 is)
 DECLARE @sql nvarchar (100)
 DECLARE @logfileid int
 SELECT @ RecoveryModel = Cast (the DATABASEPROPERTYEX (name, 'the RECOVERY') AS VARCHAR (20 is)) from WHERE name = @ DatabaseName in master..sysdatabases
 the IF @RecoveryModel <> 'the SIMPLE '
  the begin
                EXEC ( 'the ALTER DATABASE' + @ + DatabaseName 'the RECOVERY the SIMPLE the SET')
 End
 DECLARE @dsql nvarchar (200 is)
 SET @ DSQL = N'select @logfileid from file_id = '+ @ + N'.sys.database_files WHERE type_desc DatabaseName =' 'the LOG' ''
 Exec the sp_executesql @ DSQL, N '@ LogFileID The int Output', @ LogFileID The Output
 EXEC ( 'use' + @ DatabaseName + 'the DBCC SHRINKFILE (' + @ LogFileID The + ')')
FETCH Next from getDataBaseCursor INTO @databasename
End
- - in the last cursor operation, please do not forget to turn off the cursor, so that the system releases the puck resources occupied
CLOSE getDataBaseCursor
- delete cursor
DEALLOCATE getDataBaseCursor

Reproduced in: https: //www.cnblogs.com/tutuyforever/p/4797146.html

Guess you like

Origin blog.csdn.net/weixin_33895016/article/details/94682063