删除SQL大容量日志的方法(二)

2014-11-24 09:52:33 · 作者: · 浏览: 1

declare @fname nvarchar(260),@s varchar(8000)
declare tb cursor local for select fname from #t where type=64
open tb
fetch next from tb into @fname
while @@fetch_status=0
begin
set @s=del "+rtrim(@fname)+"
exec master..xp_cmdshell @s,no_output
fetch next from tb into @fname
end
close tb
deallocate tb

--附加数据库
set @s=

declare tb cursor local for select fname from #t where type=0
open tb
fetch next from tb into @fname
while @@fetch_status=0
begin
set @s=@s+,+rtrim(@fname)+
fetch next from tb into @fname
end
close tb
deallocate tb
exec(sp_attach_single_file_db +@dbname++@s)
go