set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[killspid] (@dbname varchar(20))
as
begin
declare @sql nvarchar(500)
declare @spid int
declare @c cursor --定义游标
set @c=cursor forward_only for
select spid from sysprocesses where dbid=db_id( @dbname)
open @c
--exec (@sql)
fetch next from @c into @spid
--open getspid
--fetch next from getspid into @spid
while @@fetch_status = 0
begin
EXEC ('KILL ' + @spid )
fetch next from @c into @spid
end
close @c
deallocate @c
end
set QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[killspid] (@dbname varchar(20))
as
begin
declare @sql nvarchar(500)
declare @spid int
declare @c cursor --定义游标
set @c=cursor forward_only for
select spid from sysprocesses where dbid=db_id( @dbname)
open @c
--exec (@sql)
fetch next from @c into @spid
--open getspid
--fetch next from getspid into @spid
while @@fetch_status = 0
begin
EXEC ('KILL ' + @spid )
fetch next from @c into @spid
end
close @c
deallocate @c
end
本文介绍了如何在SQL Server中使用存储过程终止特定数据库的进程,包括设置ANSI_NULLS和QUOTED_IDENTIFIER选项,定义存储过程并使用系统存储过程sysprocesses来查找并终止指定数据库的进程。

被折叠的 条评论
为什么被折叠?



