日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQLServer2008查看死鎖的存儲過程的代碼示例

SQL Server 2008數(shù)據(jù)庫中,查看死鎖可以用存儲過程來實現(xiàn),本文我們主要就介紹了SQL Server 2008查看死鎖的存儲過程的代碼示例,希望能夠?qū)δ兴鶐椭?/p>

代碼示例如下:

 
 
 
  1. if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_who_lock]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)  
  2. drop procedure [dbo].[sp_who_lock]  
  3. GO  
  4. use master  
  5. go  
  6. create procedure sp_who_lock  
  7. as  
  8. begin  
  9. declare @spid int,@bl int,  
  10. @intTransactionCountOnEntry int,  
  11. @intRowcount int,  
  12. @intCountProperties int,  
  13. @intCounter int  
  14. create table #tmp_lock_who (  
  15. id int identity(1,1),  
  16. spid smallint,  
  17. bl smallint)  
  18. IF @@ERROR<>0 RETURN @@ERROR  
  19. insert into #tmp_lock_who(spid,bl) select 0 ,blocked  
  20. from (select * from sysprocesses where blocked>0 ) a   
  21. where not exists(select * from (select * from sysprocesses where blocked>0 ) b   
  22. where a.blocked=spid)  
  23. union select spid,blocked from sysprocesses where blocked>0  
  24. IF @@ERROR<>0 RETURN @@ERROR   
  25. -- 找到臨時表的記錄數(shù)  
  26. select @intCountProperties = Count(*),@intCounter = 1 
  27. from #tmp_lock_who  
  28. IF @@ERROR<>0 RETURN @@ERROR   
  29. if @intCountProperties=0 
  30. select '現(xiàn)在沒有阻塞和死鎖信息' as message  
  31. -- 循環(huán)開始  
  32. while @intCounter <= @intCountProperties  
  33. begin  
  34. -- 取第一條記錄  
  35. select @spidspid = spid,@blbl = bl  
  36. from #tmp_lock_who where Id = @intCounter   
  37. begin  
  38. if @spid =0   
  39. select '引起數(shù)據(jù)庫死鎖的是: '+ CAST(@bl AS VARCHAR(10)) + '進程號,其執(zhí)行的SQL語法如下'  
  40. else  
  41. select '進程號SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '進程號SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其當前進程執(zhí)行的SQL語法如下'  
  42. DBCC INPUTBUFFER (@bl )  
  43. end   
  44. -- 循環(huán)指針下移  
  45. set @intCounter = @intCounter + 1  
  46. end  
  47. drop table #tmp_lock_who  
  48. return 0  
  49. end 

以上就是SQL Server 2008查看死鎖的存儲過程的代碼示例的全部內(nèi)容,本文我們就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!


網(wǎng)站題目:SQLServer2008查看死鎖的存儲過程的代碼示例
分享地址:http://www.5511xx.com/article/dhhseec.html