SQL2005查看死鎖存儲過程sp_who_lock
下面是我整理的監(jiān)控sql server數(shù)據(jù)庫,在性能測試過程中是否出現(xiàn)死鎖、堵塞的SQL語句,還算比較準備,留下來備用。
調(diào)用方法:選中相應(yīng)的數(shù)據(jù)庫,執(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ù)
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
if @intCountProperties=0
select '現(xiàn)在沒有阻塞和死鎖信息' 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 '引起數(shù)據(jù)庫死鎖的是: '+ CAST(@bl AS VARCHAR(10)) + '進程號,其執(zhí)行的SQL語法如下'
else
select '進程號SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '進程號SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其當(dāng)前進程執(zhí)行的SQL語法如下'
DBCC INPUTBUFFER (@bl )
end
-- 循環(huán)指針下移
set @intCounter = @intCounter + 1
end
drop table #tmp_lock_who
return 0
end
- SQLServer 2008數(shù)據(jù)庫降級到2005低版本
- SQL Server 2005安裝配置方法圖文教程 完美兼容Win7所有版本
- Microsoft Sql server2005的安裝步驟圖文詳解及常見問題解決方案
- SQL Server 2005 中使用 Try Catch 處理異常
- SQL Server 2005 Management Studio Express企業(yè)管理器將英文變成簡體中文版的實現(xiàn)方法
- SQL Server 2005附加數(shù)據(jù)庫時Read-Only錯誤的解決方案
- 詳解刪除SQL Server 2005 Compact Edition數(shù)據(jù)庫
相關(guān)文章
mdf文件和ldf文件導(dǎo)入到sql server 2005實現(xiàn)語句
導(dǎo)入mdf文件和ldf文件到數(shù)據(jù)庫是網(wǎng)站搬家或者是初學(xué)者學(xué)習(xí)源碼是必要的一步,接下來為大家詳細介紹實現(xiàn)sql語句,感興趣的你可不要錯過了哈希望可以幫助到你2013-03-03
Sql Server2005實現(xiàn)遠程備份數(shù)據(jù)庫
相信大家都在當(dāng)心數(shù)據(jù)庫的丟失,這也是每個開發(fā)者頭痛的一件事件,因為正在運行的服務(wù)器及數(shù)據(jù)庫也在這臺服務(wù)器上2014-04-04
SQLServer2005與SQLServer2008數(shù)據(jù)庫同步圖文教程
要實現(xiàn)SQLServer2005與2005的數(shù)據(jù)庫同步的話,直接用鏡像就可以實現(xiàn)。但是如果同步 SQLServer2008的話,2005的實例是連接不上08的。低版本的無法連接高版本的。所以我們可以通過復(fù)制的方式,也就是所謂的訂閱發(fā)布的方法來實現(xiàn)兩個不同版本數(shù)據(jù)庫的數(shù)據(jù)同步。2011-09-09
在sqlserver2005中安裝sql server 2000的示例數(shù)據(jù)庫northwind的方法
裝完sql server 2005后卻沒有找到ms的示例數(shù)據(jù)庫northwind 后來查看安裝光盤發(fā)現(xiàn)sql server 2005種只有adventurework與adventureworkDW這兩個sample database 到ms官方站找了好久 才找到sql server 2000的sample database2013-05-05
sqlserver 2005 無法在服務(wù)器上訪問指定的路徑或文件
sqlserver 2005 無法在服務(wù)器上訪問指定的路徑或文件。請確保您具有必需的安全權(quán)限且該路徑或文件存在2010-06-06
SQL Server 2005 鏡像構(gòu)建手冊(sql2005數(shù)據(jù)庫同步鏡像方案)
為了網(wǎng)站數(shù)據(jù)庫安全,我們需要備份數(shù)據(jù),這里為大家分享下sql2005數(shù)據(jù)庫同步鏡像方案,需要的朋友可以參考下2014-08-08
SQL2005 provider: 命名管道提供程序 error: 40 無法打開到 SQL Server 的連接
這篇文章主要介紹了SQL2005 provider: 命名管道提供程序 error: 40 無法打開到 SQL Server 的連接,需要的朋友可以參考下2015-01-01

