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

2014-11-24 01:41:53 · 作者: · 浏览: 21
ype=status&0x40 from [+@dbname+]..sysfiles)
  exec(sp_detach_db +@dbname+)
  --删除日志文件
  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