你可以隔几分种后执行上述代码就可以了。 或者用大力的杀进程存储过程,如下: /*************************** 杀进程存储过程 ***************************/ use master go if exists(select name from dbo.sysobjects where id=object_id(N'dbo.p_killspid') and objectproperty(id,N'IsProcedure')=1) drop proc p_killspid go create proc p_killspid (@dbname varchar(20)) as begin declare @sql nvarchar(500) declare @spid int set @sql='declare getspid cursor for select spid from sysprocesses where dbid=db_id('''+@dbname+''')' exec (@sql) open getspid fetch next from getspid into @spid declare @a varchar(100) while @@fetch_status < >-1 begin set @a='kill '+rtrim(@spid) exec(@a) fetch next from getspid into @spid end close getspid deallocate getspid end GO-- 调用 use master go exec p_killspid 'pubs'
或者用大力的杀进程存储过程,如下:
/***************************
杀进程存储过程
***************************/
use master
go
if exists(select name from dbo.sysobjects where id=object_id(N'dbo.p_killspid') and objectproperty(id,N'IsProcedure')=1)
drop proc p_killspid
go
create proc p_killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500)
declare @spid int
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
declare @a varchar(100)
while @@fetch_status < >-1
begin
set @a='kill '+rtrim(@spid)
exec(@a)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end
GO-- 调用
use master
go
exec p_killspid 'pubs'