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
SQL code
1.清空日志
DUMP TRANSACTION 库名 WITH NO_LOG
2.截断事务日志:
BACKUP LOG 数据库名 WITH NO_LOG
3. DBCC SHRINKFILE(1) 其中的1、2是SQL中的mdf 和ldf文件