sqlserver Êý¾Ý¿âËÀËøºó¶à³¤Ê±¼ä½âËø£¿
¸÷λ´óÏÀ£¬sqlserver Êý¾Ý¿âËÀËøºó£¬»á²»»á×Ô¶¯½âËøÄØ£¿¶à³¤Ê±¼äÄÜ×Ô¶¯½âËøÄØ£¿Ð»Ð»£¡
SQL code:
use master
go
create procedure 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
-- Ñ»·¿ªÊ¼
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))
+ '½ø³ÌºÅ,ÆäÖ´ÐеÄSQLÓï·¨ÈçÏÂ'
else
select '½ø³ÌºÅSPID£º'+ CAST(@spid AS VARCHAR(10))+ '±»'
+ '½ø³ÌºÅSPID£º'+ CAST(@bl AS VARCHAR(10)) +'×èÈû,Æäµ±
ǰ½ø³ÌÖ´ÐеÄSQLÓï·¨ÈçÏÂ'DBCC INPUTBUFFER
×Ô¼ºÊÔÏÂ
{{--
Ïà¹ØÎÊ´ð£º
ÏÈÓÉÈçÏÂsqlÓï¾ä
select A,B,C from table1
union
select A,B,C from table2
order by A, C asc
µÃµ½½á¹ûÈçÏ£º
A B &nbs ......
ÇëÎÊһϣ¬ÍâÍøÁ½Ì¨SQLSERVERʵÀýÊý¾Ý´«Ê䣬ÓÐûÓвÉÓÃÊý¾ÝѹËõºÍ¼ÓÃÜ¡£Ñ¹Ëõ±ÈÊǶàÉÙ£¬¼ÓÃÜÊÇʲô¼ÓÃÜËã·¨£¿Ïà¹ØÎĵµÄÄÀï¿ÉÒÔÕÒµ½£¿Ð»Ð»
ÎÒÒ²ÏëÖªµÀ£¡¹Ø×¢´ËÌù£¡
¹Ø×¢¡«¡«
Êý¾Ý¿â´óÅ£¶¼ÄÄÈ¥Á˰¡£¿
......
ÎÒµÄÊý¾Ý¿âͻȻ±¨Ò»¸öºÜÓôÃÆµÄ´íÎ󣬵¼ÖÂÊý¾ÝÎÞ·¨²é¿´£¬
´íÎóÌáʾΪ£º
ÔÚÎļþ 'G:\data\ÆóÒµ¹ÜÀíÊý¾Ý¿â1_data.n ......
ֻΪ¶úå¦Ä¿È¾£¬ÓÐËù½ø²½£¡
ßµ°Ý£¡
..
ÕâÀï¾ÍÊÇ
ÕâÀï±ÈQQȺÀïÈÈÄÖ
ÎÒÒ²ÏëÕÒÕâô¸öȺ
.
SQL code:
¡£¡£¡£¡£¡£
¡£
ºÇºÇ
ÒýÓÃ
ÕâÀï±ÈQQȺÀïÈÈÄÖ
ͬÒâ
發錯° ......