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
×Ô¼ºÊÔÏÂ
{{--
Ïà¹ØÎÊ´ð£º
±ÈÈç Óû§Ãû£¬ÎÒ³ÌÐòµÄÒªÇóÊÇ10λ×Ö·ûÒÔÄÚ£¬ËùÒÔ£º
Èç¹ûÎÒsqlserver´Óvarchar(50)´æ´¢¸ÄΪÓÃvarchar(10)µÄ»°£¬
1.»á²»»á¼õÉÙÊý¾Ý¿Õ¼ä£¿
2.»á²»»áÌá¸ßÎÒ³ÌÐòµÄЧÂÊ£¿
3.ÓÐûÓбØÒª£¿
СµÜÏÈл ......
±ÈÈç ´«½øÀ´µÄ×Ö·û´®ÊÇ ¡®12/sep/2009 12£º52£º20¡¯ Ö±½ÓÓÃcast»á±¨´í¡£
¶øÇÒÖмäµÄÔ·ÝÒ²²»¹Ì¶¨ ¡£Ôõôת»»³ÉÈÕÆÚÐ͵ÄÄØ
ÓÃÒ»¸ö±í¼Ç¼1-12Ô·ݣ¡
Ö±½Óת»»ÊDz»ÐÐÁË ²ð·Ö ³öÔÂÀ´ÅжÏÁË
¡®12/sep/2009 12£º ......
±íÖÐÊý¾Ý 700ÍòÌõ×óÓÒ£¬29¸ö×ֶΣ¬×Ô¶¯Ôö³¤ÁÐÉèΪÖ÷¼ü£¬ ʹÓÃcount£¨1£© ²éѯ×ÜÌõÊýÐèÒª1·ÖÖÓ£¬
select top 1000 ×Ö¶ÎÃû from ±í order by ʱ¼ä(¸Ã×Ö¶ÎÓÐÖظ´ÖµºÍnullÖµ) ÕâÑùµÄÓï¾ä²éѯ¸üÊÇÂýµÃ»ù± ......
ֻΪ¶úå¦Ä¿È¾£¬ÓÐËù½ø²½£¡
ßµ°Ý£¡
..
ÕâÀï¾ÍÊÇ
ÕâÀï±ÈQQȺÀïÈÈÄÖ
ÎÒÒ²ÏëÕÒÕâô¸öȺ
.
SQL code:
¡£¡£¡£¡£¡£
¡£
ºÇºÇ
ÒýÓÃ
ÕâÀï±ÈQQȺÀïÈÈÄÖ
ͬÒâ
發錯° ......
sqlserver,Èç¹û¼Ó¸öÓû§,ȨÏÞÊǶÁËùÓÐ±í£¬µ«Ö»ÄÜÐÞ¸Äij¸ö±íµÄ×Ö¶ÎÊôÐÔ
ûÕâ¸ö˵·¨.
Ö»¸øSELECT ,
UPDATEµÄÖ»¸øijЩ±í
¸ö²»»á
µ«Ö»ÄÜÐÞ¸Äij¸ö±íµÄ×Ö¶ÎÊôÐÔ Õâ¸öÄѸã
Òª¼ÓȨÏÞµÃÕë¶Ôij¸öÊý¾Ý¿â
......