SQL database Query the current environment has no deadlock

Source: Internet
Author: User

 DECLARE @spid INT ,            @bl INT ,            @intTransactionCountOnEntry INT ,            @intRowcount INT ,            @intCountProperties INT ,            @intCounter INT        CREATE TABLE#tmp_lock_who (IDINT IDENTITY(1,1), spidSMALLINT, BLSMALLINT            )        IF @ @ERROR <> 0             Print @ @ERROR        INSERT   into#tmp_lock_who (spid, BL)SELECT  0, blocked from(SELECT    *                           fromMaster.. sysprocessesWHEREBlocked> 0) AWHERE    not EXISTS(SELECT *                                      from(SELECT    *                                               fromMaster.. sysprocessesWHEREBlocked> 0) bWHEREA.blocked=spid)UNION                SELECTspid, blocked fromMaster.. sysprocessesWHEREBlocked> 0        IF @ @ERROR <> 0             Print @ @ERROR--number of records found for temporary table        SELECT  @intCountProperties = COUNT(*) ,                @intCounter = 1         from#tmp_lock_whoIF @ @ERROR <> 0             Print @ @ERROR        IF @intCountProperties = 0             SELECT  'No blocking and deadlock information now'  asmessage--Cycle Start         while @intCounter <= @intCountProperties             BEGIN--take the first record                SELECT  @spid =spid,@bl =BL from#tmp_lock_whoWHEREId= @intCounter                BEGIN                    IF @spid = 0                         SELECT  'causing the database to be slow is:' + CAST(@bl  as VARCHAR(Ten))                                + 'process number, which executes the following SQL syntax'                    ELSE                         SELECT  'process number spid:' + CAST(@spid  as VARCHAR(Ten))+ 'was'                                + 'process number spid:' + CAST(@bl  as VARCHAR(Ten))                                + 'The SQL syntax that the current process executes is blocked as follows'                    DBCCInputBuffer (@bl )                END--The loop pointer moves down                SET @intCounter = @intCounter + 1            END        DROP TABLE#tmp_lock_whoPrint 0

SQL database Query the current environment has no deadlock

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.