博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

SQL Server 清除数据库日志脚本(转)

Posted on 2009-07-24 22:39  linFen  阅读(484)  评论(0编辑  收藏  举报

SQL Server 清除数据库日志脚本(转)

Use master
go

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