首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

用kill为何报错了?解决方法

2012-03-01 
用kill为何报错了?usemastergodeclarehyccursorforselectspidfromsysprocesseswheredbiddb_id( db_test )

用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

热点排行