加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver 杀死死锁进程

发布时间:2020-12-12 13:17:21 所属栏目:MsSql教程 来源:网络整理
导读:use test2008 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 varchar(200)??? --要关闭进程

use test2008
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 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

--用法? exec p_killspid? test2008

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读