setansi_nulls
onset
quoted_identifier
ongo
create
procedure
[dbo].
[sp_who_lock]as
begin
declare
@spid
int,
@blint
,@inttransactioncountonentry
int,
@introwcount
int,
@intcountproperties
int,
@intcounter
intcreate
table
#tmp_lock_who (
id int
identity(1
,1),spid
smallint
,bl
smallint)if
@@error
<>
0return
@@error
insert
into
#tmp_lock_who(spid,bl)
select
0,blocked
from
(select
*from
sysprocesses
where
blocked
>
0) a
where
notexists
(select
*from
(select
*from
sysprocesses
where
blocked
>
0) b
where
a.blocked
=spid)
union
select
spid,blocked
from
sysprocesses
where
blocked
>0if
@@error
<>
0return
@@error
--找到臨時表的記錄數
select
@intcountproperties
=count(*
),@intcounter=1
from
#tmp_lock_who
if@@error
<>
0return
@@error
if@intcountproperties=0
select
'現在沒有阻塞和死鎖資訊'as
message
--迴圈開始
while
@intcounter
<=
@intcountproperties
begin
--取第一條記錄
select
@spid
=spid,
@bl=
blfrom
#tmp_lock_who
where
id =
@intcounter
begin
if@spid=0
select
'引起資料庫死鎖的是: '+
cast
(@bl
asvarchar(10
)) +
'程序號,其執行的sql語法如下
'else
select
'程序號spid:'+
cast
(@spid
asvarchar(10
))+'被
'+'程序號spid:'+
cast
(@bl
asvarchar(10
)) +
'阻塞,其當前程序執行的sql語法如下
'dbcc
inputbuffer (
@bl)
end--
迴圈指標下移
set@intcounter
=@intcounter+1
enddrop
table
#tmp_lock_who
return
0end
乙個儲存過程
create or replace package abc zys is procedure daily census end abc zys 建乙個包,包中有儲存過程daily census。不涉及任何引數。create or replace package body abc zys is pro...
乙個儲存過程
首先是建立儲存過程.drop procedure if exists externalcalltocomplete delimiter create procedure externalcalltocomplete begin drop table if exists temp1 create ta...
死鎖的儲存過程
exec sp who lock use master gocreate procedure sp who lock asbegin declare spid int,bl int,inttransactioncountonentry int,introwcount int,intcountprop...