--此儲存過程執行完可以看到資料庫鎖表情況
create procedure sp_who_lock
asbegin
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 sys.sysprocesses
where blocked > 0
) awhere not exists ( select *
from ( select *
from sys.sysprocesses
where blocked > 0
) bwhere a.blocked = spid )
union
select spid, blocked
from sys.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 n'現在沒有阻塞和死鎖資訊' as message
-- 迴圈開始
while @intcounter <= @intcountproperties
begin
-- 取第一條記錄
select @spid = spid, @bl = bl
from #tmp_lock_who
where id = @intcounter
begin
if @spid = 0
select n'引起資料庫死鎖的是: ' + cast(@bl as varchar(10))
+ n'程序號,其執行的sql語法如下'
else
select n'程序號spid:' + cast(@spid as varchar(10))
+ n'被程序號spid:' + cast(@bl as varchar(10)) n'阻塞,其當前程序執行的sql語法如下'
dbcc inputbuffer (@bl )
end-- 迴圈指標下移
set @intcounter = @intcounter + 1
enddrop table #tmp_lock_who
return 0
end
查詢資料庫鎖表
對於資料庫的造作,鎖表了怎麼辦?1.檢視當前系統中鎖表情況 select l.session id sid,s.serial l.locked mode,l.oracle username,l.os user name,s.machine,s.terminal,o.object name,s.log...
查詢資料庫鎖表資訊
查詢資料庫鎖表資訊 create proc dbo sp lockinfo kill lock spid bit 0,是否殺掉死鎖的程序 1 殺掉 0 僅顯示 show spid if nolock bit 0 如果沒有死鎖的程序,是否顯示正常的 1 顯示 0 不顯示 asset nocount o...
Oracle資料庫鎖表查詢
檢視資料庫最大連線數 select value from v parameter where name processes 更改資料庫連線數 alter system set processes 3000 scope spfile 檢視被鎖的表 select b.owner,b.object nam...