读书人

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

发布时间: 2012-03-01 10:25:47 作者: rapoo

用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

读书人网 >SQL Server

热点推荐