一个数据库解锁的存储过程sp_who_lock
来源:互联网 发布:物流软件功能 编辑:程序博客网 时间:2024/05/20 20:58
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
create procedure sp_who_lock
as
begin
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int
create table #tmp_lock_who (id int identity(1,1),spid smallint,bl smallint)
IF @@ERROR<>0 RETURN @@ERROR
insert into #tmp_lock_who(spid,bl) select 0 ,blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from sysprocesses where blocked>0
IF @@ERROR<>0 RETURN @@ERROR
-- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
if@intCountProperties=0
select '现在没有阻塞和死锁信息' as message
-- 循环开始
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where id = @intCounter
begin
if @spid =0
select '引起数据库死锁的是: '+ CAST(@bl AS VARCHAR(10)) + '进程号,其执行的SQL语法如下'
else
select '进程号SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '进程号SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其当前进程执行的SQL语法如下'
DBCC INPUTBUFFER (@bl )
end
-- 循环指针下移
set @intCounter = @intCounter + 1
end
drop table #tmp_lock_who
return 0
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
死锁的
- 一个数据库解锁的存储过程sp_who_lock
- 一个数据库解锁的存储过程sp_who_lock
- 查看数据库死锁的存储过程SP_WHO_LOCK
- 查看死锁存储过程 sp_who_lock
- 存储过程解锁
- 存储过程解锁
- sp_who_lock
- sp_who_lock
- 可以自定义导出数据库存储过程(含加密过程)的一个存储过程
- 数据库的存储过程
- 数据库的存储过程。
- 数据库的存储过程
- 数据库的存储过程
- 数据库的存储过程
- 数据库的存储过程
- 数据库 的存储过程
- 数据库的存储过程
- 数据库的存储过程
- 一个把中文字符串转成拼音串的函数
- 数据库中死锁的查找及处理
- 交叉报表sql语句使用
- mantis中人员名称能否显示真实姓名
- Spring之struts+hibernate+spring添删改查示例(二)
- 一个数据库解锁的存储过程sp_who_lock
- 一个屏蔽部分电话号码的函数
- ERP实施 浅谈实施顾问的三大核心素质[转]
- 用TestDirector的测试管理的流程
- Java 调用 Oracle 存储过程返回结果集
- Spring之struts+hibernate+spring添删改查示例(一)
- Oracle 10g正则表达式
- ASp.NET 使用存储过程相关知识
- [ 活动 ] CSDN 用户体验有奖调查 / 幸运者将获得200 C币