假如发生了死锁,我们怎么去检测具体发生死锁的是哪条sql语句或存储过程?此时我们可以使用以下存储过程来检测,就可以查出引起死锁的进程和sql语句.sql代码?
- 情感问答
- 答案列表
死锁查询[朗读]
execsp_lock快捷键c_2execsp_whoactiveexecsp_who快捷键c_1用profiler里面的locks->deadlockgraph监控看看,如果看到了死锁图,就可以比较形象地展现死锁。
--查询出死锁的spidselectblockedfrom(select*fromsysprocesseswhereblocked>0)awherenotexists(select*from(select*fromsysprocesseswhereblocked>0)bwherea.blocked=spid)。
为了查看死锁信息,数据库引擎提供了监视工具,分别为两个跟踪标志以及sqlserverprofiler中的死锁图形事件.跟踪标志1204和跟踪标志1222发生死锁时,跟踪标志。
declare@spidintdeclare@blkintdeclare@countintdeclare@indexintdeclare@@@errorif@count=0beginselect'没有阻塞和死锁信息'--return0endwhile@index<=。