How to create blocking in SQL

  • Hi,

    I would like to test my SP which can capture the blocking. But how I can create a blocking scenario via SQL script?

    Thanks

  • 1) Why write your own script? Just use sp_whoisactive!! AMAZING FREE script from Adam Machanic.

    2) You typically need to use 2 connections to create blocking.

    spid1:

    BEGIN TRAN

    SELECT *

    FROM myTable WITH (TABLOCKX)

    WHERE something

    spid2:

    BEGIN TRAN

    SELECT *

    FROM myTable WITH (TABLOCKX)

    WHERE samething

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply