Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://blog.waynesheffield.com/wayne/code-library/shred-deadlock-graph/" rel="nofollow noreferrer">Shredding your deadlock graph</a> into tabular form shows the following.</p> <pre><code>+----------+-------------------------+-----------+-----------+------------+----------+--------------------+--------------------+---------+ | LockMode | LockedObject | TranCount | LockEvent | LockedMode | WaitMode | WaitResource | IsolationLevel | LogUsed | +----------+-------------------------+-----------+-----------+------------+----------+--------------------+--------------------+---------+ | U | MYDATABASE.dbo.MyNumber | NULL | rid | X | U | RID: 5:1:127478:20 | read committed (2) | 192 | | U | MYDATABASE.dbo.MyNumber | NULL | rid | X | U | RID: 5:1:127478:16 | read committed (2) | 1848 | +----------+-------------------------+-----------+-----------+------------+----------+--------------------+--------------------+---------+ </code></pre> <p>You still haven't answered my question in the comments as to whether the sequence generation code is only called once in every transaction.</p> <p>It is easy to generate a deadlock graph similar to the one in your post if not.</p> <h2>Setup</h2> <pre><code>CREATE TABLE dbo.MyNumber ( [TYPE] CHAR(1), YRCLOSEDYN INT, NEXTNO INT ) INSERT INTO dbo.MyNumber VALUES ('X', 0, 1), ('Y', 0, 1) GO CREATE PROC MyStoredProcedure @TYPE CHAR(1), @NEXTNO INT OUTPUT AS UPDATE dbo.MyNumber SET @NEXTNO = NEXTNO = NEXTNO + 1 WHERE ( [TYPE] = @TYPE ) AND ( YRCLOSEDYN = 0 ) </code></pre> <h2>Connection 1</h2> <pre><code>BEGIN TRAN DECLARE @NEXTNO INT EXEC MyStoredProcedure 'Y', @NEXTNO OUTPUT WAITFOR DELAY '00:00:05' EXEC MyStoredProcedure 'X', @NEXTNO OUTPUT ROLLBACK </code></pre> <h2>Connection 2</h2> <p>(Run immediately after executing the code in connection 1)</p> <pre><code>BEGIN TRAN DECLARE @NEXTNO INT EXEC MyStoredProcedure 'X', @NEXTNO OUTPUT EXEC MyStoredProcedure 'Y', @NEXTNO OUTPUT ROLLBACK </code></pre> <p>The deadlock graph output from that is very similar to the one above</p> <pre><code>+----------+-------------------------+-----------+-----------+------------+----------+-----------------+--------------------+---------+ | LockMode | LockedObject | TranCount | LockEvent | LockedMode | WaitMode | WaitResource | IsolationLevel | LogUsed | +----------+-------------------------+-----------+-----------+------------+----------+-----------------+--------------------+---------+ | U | MYDATABASE.dbo.MyNumber | 2 | rid | X | U | RID: 11:1:144:1 | read committed (2) | 248 | | U | MYDATABASE.dbo.MyNumber | 2 | rid | X | U | RID: 11:1:144:0 | read committed (2) | 248 | +----------+-------------------------+-----------+-----------+------------+----------+-----------------+--------------------+---------+ </code></pre> <p>If this is the explanation for your issue you will need to ensure that you update the Sequences in the same order in all transactions (I assume there must be some good reason why you can't just use <a href="https://stackoverflow.com/a/3462957/73226">an <code>IDENTITY</code> column based solution</a>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload