日期:2014-05-18  浏览次数:20508 次

用kill为何报错了?
use   master
go
declare   hyc   cursor   for
select   spid   from   sysprocesses   where   dbid=db_id( 'db_test ')
declare   @sd   int
open   hyc
while   @@fetch_status=0
begin
fetch   next   from   hyc   into   @sd
kill   @sd   --这里报错
end
close   hyc
deallocate   hyc

------解决方案--------------------

use master
go
declare hyc cursor for
select spid from sysprocesses where dbid=db_id( 'db_test ')
declare @sd int
open hyc
fetch next from hyc into @sd
while @@fetch_status=0
begin
exec( 'kill '+@sd) --这里报错
fetch next from hyc into @sd
end
close hyc
deallocate hyc