用脚本缩小数据库日志

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 happy_david 的 blog

  因为客户使用的数据库时常因为日志过大而导致硬盘空间不够,或者备份出来的文件太大无法通过邮件传送。

  闲下有余,参考sqlserver的帮助文件,写了如下脚本,可以截断日志,以达到缩小文件的目的。有空大家可以在自己的sqlserver上测试下效果哦。。。:)也许对有些情况导致的日志过大没有作用,这点可以同各位同仁互相交流下。

--在master数据库中执行以下脚本(使用查询分析器)
declare @dbname varchar(50)
declare temp_cur cursor scroll for select name from sysdatabases
open temp_cur
fetch first from temp_cur into @dbname
while @@fetch_status =0
begin
  exec ('backup log '+@dbname+' with no_log')
  exec ('dbcc shrinkdatabase('+@dbname+')')
  exec ('dbcc checkcatalog ('+@dbname+')')
  exec ('dump transaction '+@dbname+' with no_log')
  fetch next from temp_cur into @dbname
end
close temp_cur
deallocate temp_cur

本文关键:ms sqlserver ,缩小日志
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top