标签:
1 --在作业中 执行下面SQL代码 即可实现 自动收缩日志文件。(MSSQL 维护计划中没有提供自动收缩日志文件的功能) 2 --非 镜像 复制订阅 日志传送的情况下 执行。 如果存在日志传送莫要执行 否则日志传送会失败 3 declare @exec_sql nvarchar(1200),@simple_sql nvarchar(1200),@full_sql nvarchar(1200) 4 declare @db_name varchar(128) 5 declare @db_count int 6 select @db_count=COUNT(1) from sys.databases where database_id >4 7 declare @j int 8 set @j =1 9 10 while @j<=@db_count 11 begin 12 select @db_name=name from (select ROW_NUMBER() over(order by name)rn,name from sys.databases where database_id >4 )as tmp where rn=@j 13 SET @simple_sql=N‘ use [master] ‘ + Char(10) + Char(13) +‘Alter DATABASE [‘+@db_name+‘] SET RECOVERY SIMPLE WITH NO_WAIT‘ 14 EXEC Sp_executesql @simple_sql,N‘@db_name varchar(128)‘,@db_name 15 16 SET @exec_sql=N‘USE [‘+@db_name+‘]‘+ Char(10) + Char(13) +‘DBCC SHRINKFILE (N‘‘‘+@db_name+‘_log‘‘ , 0, TRUNCATEONLY)‘ 17 EXEC Sp_executesql @exec_sql,N‘@db_name varchar(128)‘,@db_name 18 19 SET @full_sql =N‘ use [master] ‘ + Char(10) + Char(13) +‘Alter DATABASE [‘+@db_name+‘] SET RECOVERY FULL WITH NO_WAIT‘ 20 EXEC Sp_executesql @full_sql,N‘@db_name varchar(128)‘,@db_name 21 22 set @j =@j+1 23 end
标签:
原文地址:http://www.cnblogs.com/zengb/p/4307015.html