1 --the following SQL code is executed in the job to enable automatic shrinking of the log files. (The ability to automatically shrink log files is not available in the MSSQL maintenance plan)2 --non-mirrored replication subscriptions are executed in the case of log shipping. Log shipping fails if log shipping does not exist3 Declare @exec_sql nvarchar( -),@simple_sql nvarchar( -),@full_sql nvarchar( -)4 Declare @db_name varchar( -)5 Declare @db_count int6 Select @db_count=COUNT(1) fromsys.databaseswheredatabase_id>47 Declare @j int8 Set @j =19 Ten while @j<=@db_count One begin A Select @db_name=Name from(SelectRow_number () Over(Order byName) Rn,name fromsys.databaseswheredatabase_id>4) asTmpwhereRn=@j - SET @simple_sql=N'Use [master]' + Char(Ten)+ Char( -)+'Alter DATABASE ['+@db_name+'] SET RECOVERY simple with no_wait' - EXECsp_executesql@simple_sqlN'@db_name varchar (+)',@db_name the - SET @exec_sql=N'Use ['+@db_name+']'+ Char(Ten)+ Char( -)+'DBCC shrinkfile (N" "+@db_name+'_log"', 0, truncateonly)' - EXECsp_executesql@exec_sqlN'@db_name varchar (+)',@db_name - + SET @full_sql =N'Use [master]' + Char(Ten)+ Char( -)+'Alter DATABASE ['+@db_name+'] SET RECOVERY full with no_wait' - EXECsp_executesql@full_sqlN'@db_name varchar (+)',@db_name + A Set @j =@j+1 at End
SQL Server implementation automatically shrinks database log files