SQL2005查看死鎖存儲(chǔ)過(guò)程sp_who_lock
下面是我整理的監(jiān)控sql server數(shù)據(jù)庫(kù),在性能測(cè)試過(guò)程中是否出現(xiàn)死鎖、堵塞的SQL語(yǔ)句,還算比較準(zhǔn)備,留下來(lái)備用。
調(diào)用方法:選中相應(yīng)的數(shù)據(jù)庫(kù),執(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 -- 找到臨時(shí)表的記錄數(shù) select @intCountProperties = Count(*),@intCounter = 1 from #tmp_lock_who IF @@ERROR<>0 RETURN @@ERROR if @intCountProperties=0 select '現(xiàn)在沒(méi)有阻塞和死鎖信息' as message -- 循環(huán)開(kāi)始 while @intCounter <= @intCountProperties begin -- 取第一條記錄 select @spid = spid,@bl = bl from #tmp_lock_who where Id = @intCounter begin if @spid =0 select '引起數(shù)據(jù)庫(kù)死鎖的是: '+ CAST(@bl AS VARCHAR(10)) + '進(jìn)程號(hào),其執(zhí)行的SQL語(yǔ)法如下' else select '進(jìn)程號(hào)SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '進(jìn)程號(hào)SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其當(dāng)前進(jìn)程執(zhí)行的SQL語(yǔ)法如下' DBCC INPUTBUFFER (@bl ) end -- 循環(huán)指針下移 set @intCounter = @intCounter + 1 end drop table #tmp_lock_who return 0 end
- SQLServer 2008數(shù)據(jù)庫(kù)降級(jí)到2005低版本
- SQL Server 2005安裝配置方法圖文教程 完美兼容Win7所有版本
- Microsoft Sql server2005的安裝步驟圖文詳解及常見(jiàn)問(wèn)題解決方案
- SQL Server 2005 中使用 Try Catch 處理異常
- SQL Server 2005 Management Studio Express企業(yè)管理器將英文變成簡(jiǎn)體中文版的實(shí)現(xiàn)方法
- SQL Server 2005附加數(shù)據(jù)庫(kù)時(shí)Read-Only錯(cuò)誤的解決方案
- 詳解刪除SQL Server 2005 Compact Edition數(shù)據(jù)庫(kù)
相關(guān)文章
SQL Server 2005恢復(fù)數(shù)據(jù)庫(kù)詳細(xì)圖文教程
這篇文章主要介紹了SQL Server 2005恢復(fù)數(shù)據(jù)庫(kù)詳細(xì)圖文教程,需要的朋友可以參考下2014-11-11SQL Server 移動(dòng)系統(tǒng)數(shù)據(jù)庫(kù)
SQL Server中系統(tǒng)數(shù)據(jù)庫(kù)有master、model、msdb、tempdb四個(gè)數(shù)據(jù)庫(kù),對(duì)于一般的庫(kù),我們要移動(dòng)他們的位置,只需分離附加即可,而這些系統(tǒng)數(shù)據(jù)庫(kù)沒(méi)有分離的選項(xiàng),那要怎么移動(dòng)他們呢?2016-05-05SQL2005查詢(xún)表結(jié)構(gòu)的SQL語(yǔ)句使用分享
分享一個(gè)SQL2005查詢(xún)表結(jié)構(gòu)的SQL語(yǔ)句,大家參考使用吧2013-11-11SqlServer2005 自動(dòng)備份并存儲(chǔ)另一電腦上的存儲(chǔ)過(guò)程函數(shù)
SqlServer2005自動(dòng)備份并存儲(chǔ)另一電腦上的存儲(chǔ)函數(shù),想要備份的朋友可以參考下。2011-06-06SQL 2005 ERROR:3145 解決辦法(備份集中的數(shù)據(jù)庫(kù)備份與現(xiàn)有的數(shù)據(jù)庫(kù)不同)
在圖形界面中,選擇備份文件,設(shè)置覆蓋原有數(shù)據(jù)庫(kù),指定現(xiàn)數(shù)據(jù)庫(kù)文件所在的位置,選擇錯(cuò)誤回滾,點(diǎn)擊確定2013-01-01關(guān)于sqlserver 2005 使用臨時(shí)表的問(wèn)題( Invalid object name #temptb)
最近在利用 SSRS 2005 做報(bào)表的時(shí)候,調(diào)用帶有臨時(shí)表的數(shù)據(jù)源時(shí),系統(tǒng)會(huì)報(bào)錯(cuò),并無(wú)法進(jìn)入向?qū)У南乱徊?提示There is an error in the query. Invalid object name #temptb2012-07-07sysservers 中找不到服務(wù)器,請(qǐng)執(zhí)行 sp_addlinkedserver 將該服務(wù)器添加到sysserver
sysservers 中找不到服務(wù)器,請(qǐng)執(zhí)行 sp_addlinkedserver 將該服務(wù)器添加到sysserver 錯(cuò)誤的解決方法2011-09-09