I need to test my C# code in a SQL Server deadlock scenario. Is there a way to create a deadlock "on demand"?

I have tried this:

Begin Transaction 
Select * from TABLEA with (tablockx, holdlock)
Where 0 = 1
WaitFor Delay '00:02:00'
--Rollback Transaction

But the second connection just waits and until after the Delay, and then does its job.

In the second session I do

Update TABLEA 
Set LastUpdatedBy = 'IT_TESTING'
Where OrderRefProviderId = 397685
WaitFor Delay '00:00:30'
  • 3
    Brent has an easy script to illustrate what you are trying to do.Here's another on Stackoverflow
    – S3S
    Oct 28, 2019 at 16:23
  • 1
    @scsimon damn it missed the last step. If you wanna put the links in an answer with a little blurb, I will credit you for your time.
    – user111478
    Oct 28, 2019 at 16:25
  • No problem at all. Happy to help!
    – S3S
    Oct 28, 2019 at 16:26