use master
go

if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[P_KillConnections]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[P_KillConnections]
GO

create proc P_KillConnections
@dbname varchar(200)
as
declare @sql nvarchar(500)
declare @spid nvarchar(20)

declare #tb cursor for
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
open #tb
fetch next from #tb into @spid
while @@fetch_status=0
begin
exec('kill '+@spid)
fetch next from #tb into @spid
end
close #tb
deallocate #tb
go

--Usage
exec P_KillConnections 'gpsdb2_pub'

相关文章:

  • 2021-09-10
  • 2021-08-02
  • 2021-11-23
  • 2021-06-28
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
相关资源
相似解决方案