Simulate Blocking in SQL Server

There can be various scenarios where a DBA Needs to simulate Blocking in SQL Server.

Below are the Step by Step Instruction to simulate blocking in SQL Server

Step1:

Lets Create a Table and Insert Some Values in it to start our Blocking SImulates

Open a New Query Window and Execute the below code.

CREATE TABLE SIMULATEBLOCK
(
ID int identity(1,1)
,Value nvarchar(50)
)
GO
INSERT INTO SIMULATEBLOCK(Value) values
('FirstValue')
,('SecondValue')
,('ThirdValue')
,('FourthValue')
GO
Select * from SIMULATEBLOCK

Step2:

Now Open Another New Query Window for same database where you have created above table and execute below Code

BEGIN TRAN
UPDATE SIMULATEBLOCK SET Value = 'BLOCKEDVALUE' WHERE ID = 4
--ROLLBACK

Step3:

Open another New Query Window for same database and execute below code

SELECT * FROM SIMULATEBLOCK

To stop Blocking stop either of the query for Run the commented ROLLBACK statement in step 2