快速修改数据库日志的增长修改为50M[转]

 

尚未亲测..请君慎重使用..

 

SET NOCOUNT ON  
DECLARE @i INT,@iMax INT,@dbName NVARCHAR(200), @sqlTotal NVARCHAR(MAX),@sqlSingle NVARCHAR(MAX),@sql NVARCHAR(MAX)  
DECLARE @t TABLE (rowNum INT IDENTITY(1,1), dbName NVARCHAR(200))  
INSERT INTO @t (dbName)  
SELECT d.name FROM sys.databases AS d WHERE d.name NOT IN  ('master','tempdb','model','msdb')  
SELECT @i=1,@iMax=MAX(rowNum),@sqlTotal='',@sqlSingle='' FROM @t  
  
WHILE @i<=@iMax  
BEGIN  
    SELECT @dbName=dbName FROM @t WHERE rowNum=@i  
    SET @sql='use '+@dbName+' SET @sqlSingle= (SELECT ''ALTER DATABASE ['+@dbName+'] MODIFY FILE ( NAME = N{''+s.name+''}, FILEGROWTH = 51200KB );'' FROM sys.sysfiles s FOR XML PATH('''') )'  
    EXEC sys.sp_executesql @sql, N'@sqlSingle nvarchar(max) out', @sqlSingle OUT  
    SET @sqlTotal=@sqlTotal+@sqlSingle  
    SET @i=@i+1  
END  
SET @sqlTotal=REPLACE(REPLACE( REPLACE(@sqlTotal,';','  
'),'{',''''),'}','''')  
PRINT @sqlTotal  
EXEC (@sqlTotal)  

 

posted @ 2017-01-13 11:51  代码工人有力量  阅读(378)  评论(0编辑  收藏  举报