USE [master]
GO
/****** Object: StoredProcedure [dbo].[sp_who_lock] Script Date: 05/12/2016 14:13:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO ALTER procedure [dbo].[sp_who_lock]
as
begin
--exec sp_who_lock 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

最新文章

  1. JavaScript中String对象的方法介绍
  2. (转)Java:类与继承
  3. 大熊君大话NodeJS之------MongoDB模块(额外篇)
  4. uva 1339
  5. lvs之ip-tun(ip隧道)技术的学习与实践
  6. hdu 3853LOOPS (概率DP)
  7. ELK:kibana使用的lucene查询语法
  8. 6个WordPress备份插件
  9. Spring+SpringMVC+Mybatis 利用AOP自定义注解实现可配置日志快照记录
  10. 关于sql、mysql语句的模糊查询分类与详解,包括基本用法和mapper.xml文件里插入写法
  11. linux自动化创建补丁
  12. Pytorch--Dropout笔记
  13. Swift Enum 枚举
  14. js 闭包 弊端
  15. 阿里云容器服务区块链解决方案全新升级 支持Hyperledger Fabric v1.1
  16. delphi 启动停止windows服务 转
  17. Windows 10 修改系统环境变量后,CMD生效,Powershell未生效
  18. SQLSERVER的四个系统数据库
  19. POJ 1160 经典区间dp/四边形优化
  20. JS返回一个数据的千分位格式

热门文章

  1. JAVA-数组或集合
  2. CodeForces 785E Anton and Permutation 分块
  3. CodeForces 785C Anton and Fairy Tale 二分
  4. ceph 存储系统
  5. 滑动菜单栏之开源项目SlidingMenu的使用
  6. python之if测试
  7. Linux利用OneinStack搭建环境
  8. centos6系列问题
  9. 操作App.config的类(转载)
  10. linux 出错 “INFO: task xxxxxx: 634 blocked for more than 120 seconds.”的3种解决方案(转)