title: How to simulate DEADLOCK on SQL Server?
body: <p>I am trying to simulate a deadlock on SQL Server.</p>
  
  <pre><code>_|worker_id|salary|
  1|1        |100   |
  2|2        |300   |
  </code></pre>
  
  <p>Transaction 1 completed in 5 seconds.</p>
  
  <pre><code>/* TRANSACTION 1*/
  Use dbmcw;
  
  DECLARE @sal1 INT, @sal2 int;
  
  BEGIN TRAN;
  
  SELECT @sal1 = salary
  FROM dbo.deadlock_demonstration WITH(UPDLOCK) 
  WHERE worker_id = 1;
  
  WAITFOR DELAY '00:00:05.000';
  
  SELECT @sal2 = salary
  FROM dbo.deadlock_demonstration WITH(UPDLOCK)
  WHERE worker_id = 2;
  
  COMMIT TRAN;
  </code></pre>
  
  <p>Transaction 2 finished in 3 seconds.</p>
  
  <pre><code>/* TRANSACTION 2*/
  Use dbmcw;
  
  DECLARE @sal1 INT, @sal2 int;
  
  BEGIN TRAN;
  
  SELECT @sal2 = salary
  FROM dbo.deadlock_demonstration WITH(UPDLOCK)
  WHERE worker_id = 2;
  
  SELECT @sal1 = salary
  FROM dbo.deadlock_demonstration WITH(UPDLOCK)
  WHERE worker_id = 1;
  
  COMMIT TRAN;
  </code></pre>
  
  <p>SQL Server is not giving any error. Deadlock did not occur. What should I change in order to simulate a deadlock?</p>