I would like to share the steps to find/detect the deadlocks in SQL Server. It is very easy to find the deadlock using SQL Profiler.
Step #7:
Now run following queries to generate deadlock.
CREATE TABLE dbo.foo (col1 INT)
INSERT dbo.foo SELECT 1
CREATE TABLE dbo.bar (col1 INT)
INSERT dbo.bar SELECT 1
— 2) Run in first connection window
BEGIN TRAN
UPDATE foo SET col1 = 1
— 3) Run in second connection window
BEGIN TRAN
UPDATE bar SET col1 = 1
UPDATE foo SET col1 = 1
–4) Run in first connection window
UPDATE bar SET col1 = 1
When you will run all 3 above given queries then it will give you a deadlock message. Now you can find the deadlock.xdl file in “C:\” drive as below:
There you go. Dead lock has been identified. Now you can easily detect the deadlocks on production server.
Happy Programming!!!