/*
断开所有用户打开的连接
*/
use master
go
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_killspid]
GO
create proc p_killspid
@dbname sysname --要关闭进程的数据库名
as
declare @s nvarchar(1000)
declare tb cursor local for
select s='kill '+cast(spid as varchar)
from master..sysprocesses
where dbid=db_id(@dbname)
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
go
--用法
exec p_killspid 'hj'
断开所有用户打开的数据库连接
最新推荐文章于 2021-01-28 03:29:16 发布
本文介绍了一个用于关闭数据库连接的SQL存储过程,包括如何使用该存储过程、其内部工作原理以及具体实现代码。
6816

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



