SQL Server 2008 viewing deadlock stored Procedures

Source: Internet
Author: User

Use [master]go/****** Object:  storedprocedure [dbo]. [Sp_who_lock]    script date:07/30/2015 13:52:38 ******/set ansi_nulls ongoset quoted_identifier ONGOALTER Pro cedure [dbo]. [Sp_who_lock]asbegindeclare @spid int, @bl int,        @intTransactionCountOnEntry int,        @intRowcount int,        @intCountProperties int,        @intCounter Intcreate table #tmp_lock_who (id int identity (), spid smallint,bl smallint)  if @ @ERROR <>0 RETURN @ @ERROR & Nbsp;insert to #tmp_lock_who (SPID,BL) Select 0, Blockedfrom (SELECT * from sysprocesses where blocked>0) Awhere not Exi STS (SELECT * from sysprocesses where blocked>0) b where a.blocked=spid) union select spid,blocked from SYS Processes where blocked>0if @ @ERROR <>0 RETURN @ @ERROR   --Find the number of records for the staging table Select @intCountProperties = Count (*), @intCounter = 1from #tmp_lock_who  if @ @ERROR <>0 RETURN @ @ERROR   if @intCountProperties =0select ' now has no blocking and deadlock information ' as message--cycle starts while @intCounter <= @intCountPropertiesbegin-- Take the first record  select @spid = spid, @bl =bl from #tmp_lock_who where [email protected]beginif @spid =0 select ' The resulting database deadlock is: ' + cast (@bl as varchar (10) + ' process number, which executes the SQL syntax as follows ' else select ' process number spid: ' + cast (@spid as varchar (10) + ' + ') The process number spid: ' + CAST (@bl as VARCHAR (10)) + ' block, its current process executes the SQL syntax as follows ' DBCC InputBuffer (@bl) end--The loop pointer moves down set @intCounter = @intCounter + 1enddrop Table #tmp_lock_whoreturn 0end

SQL Server 2008 viewing deadlock stored procedures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.