内容显示页
 
类别:数据库+SQL | 浏览(182) | 2008-7-7 13:49:49 | 关闭广告

有些数据库的日志增加很快,有些服务器的数据库很多,有几十个,如果一个一个的收缩数据库,很慢,很累,很无聊。

declare cur cursor for select name from Master..SysDatabases where name<>'master' and name<>'model' and name<>'msdb' and name<>'Northwind' and name<>'pubs'
declare @tb sysname 

open cur 
fetch next from cur into @tb 
while @@fetch_status=0 
begin 
  exec ('dump transaction ['+@tb+'] with no_log') 
  exec ('backup log ['+@tb+'] with no_log') 
  exec ('dbcc shrinkdatabase(['+@tb+'])') 
  fetch next from cur into @tb 
end 
close cur 
deallocate cur

 


引用本页地址:http://www.yongfa365.com/item/MSSQL-Shrink-All-Database-yongfa365.html
 
 
相关链接
 
网友评论:
姓名: 记住我
网址:
邮箱:
内容:
验证码:  验证码图片看不清? 换张图试试
 
   
 
 
文章分类
 
   

Power by :柳永法(yongfa365)'Blog | Model by :hibaidu | CSS by:众网友 | 京ICP备07011491号  QQ:64049027  E-mail:64049027qq.com

本空间赞助商:北京中科兴联信息技术有限公司