佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > SQL2005查看死鎖存儲過程sp_who_lock

SQL2005查看死鎖存儲過程sp_who_lock

熱門標簽:地方門戶網站 呼叫中心市場需求 鐵路電話系統 Linux服務器 服務外包 AI電銷 網站排名優(yōu)化 百度競價排名

下面是我整理的監(jiān)控sql server數據庫,在性能測試過程中是否出現死鎖、堵塞的SQL語句,還算比較準備,留下來備用。

調用方法:選中相應的數據庫,執(zhí)行exec sp_who_lock

USE [master]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE procedure [dbo].[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 

-- 循環(huán)開始 
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)) + '進程號,其執(zhí)行的SQL語法如下' 
		else 
      select '進程號SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '進程號SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其當前進程執(zhí)行的SQL語法如下' 
		DBCC INPUTBUFFER (@bl ) 
	end 

	-- 循環(huán)指針下移 
	set @intCounter = @intCounter + 1 
end 

drop table #tmp_lock_who 

return 0 
end

您可能感興趣的文章:
  • SQLServer 2008數據庫降級到2005低版本
  • SQL Server 2005安裝配置方法圖文教程 完美兼容Win7所有版本
  • Microsoft Sql server2005的安裝步驟圖文詳解及常見問題解決方案
  • SQL Server 2005 中使用 Try Catch 處理異常
  • SQL Server 2005 Management Studio Express企業(yè)管理器將英文變成簡體中文版的實現方法
  • SQL Server 2005附加數據庫時Read-Only錯誤的解決方案
  • 詳解刪除SQL Server 2005 Compact Edition數據庫

標簽:銅川 黃山 衡水 仙桃 崇左 湖南 蘭州 湘潭

巨人網絡通訊聲明:本文標題《SQL2005查看死鎖存儲過程sp_who_lock》,本文關鍵詞  ;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    万宁市| 西宁市| 神木县| 崇阳县| 泰安市| 化隆| 凌云县| 郴州市| 新邵县| 长武县| 赤壁市| 安宁市| 饶阳县| 昌江| 青神县| 九龙城区| 西和县| 岢岚县| 电白县| 邮箱| 大田县| 涿鹿县| 绵竹市| 连城县| 海口市| 屏东市| 岚皋县| 大厂| 古交市| 体育| 洛扎县| 雅江县| 崇阳县| 依兰县| 石嘴山市| 江陵县| 西乌珠穆沁旗| 阿坝| 辽中县| 闽侯县| 扶绥县|