sql server - How to solve insert/delete deadlock on non-clustered index? -
I have found a deadlock problem and I came to know that this is due to two stored procedures called different threads (2 named web services). ).
- Merge which inserts data in the X table.
- Delete that deletes data in the X table.
In addition to this, I got the result which happened to me in the non-unique and non-clustered index of X Table. Do you have any ideas to solve this problem?
From Update
, I think the error is due to the following statements.
- In the inclusion statement, the ID (clustering index) and then the non-cluster index is found.
- In the deleted statement, it is non-clustered before the id.
Therefore, I have to select the statement of deletion as the following statement, to select the ID.
SELECT id FROM X with (NOLOCK) WHERE [condition]
PS Both stored procedures are called in the transaction.
Thanks,
You must see ... you mention the transaction; Is there a level of separation? One thing to try is to signal any query that connects (UPDLOCK)
that you use to line (or check the existence); You will take a lock lock (instead of reading locks) from the beginning.
When elections are fought, then it should be blocked (very brief) instead of a deadlock.