I have a deadlock problem between an insert and a select
Connection A:
- Inserts a record in table MyTable (X lock on record)
- Updates the non-clustered index MyTable_Index (requests X lock on index entry)
Connection B:
- Uses MyTable_Index to locate records with a specific Destination (column of MyTable) (S lock on index entry)
- Returns (SELECT) the MyTable record through the index. (this is a subquery that subsequentially updates the record) (requests S lock on record)
So when A inserts (step 1) and B uses the index (step 1), a deadlock seems to occur. Connection A and B both use a ROWLOCK hint.
Is there a way to specify for connection B that MyTable_Index should not be locked, like a NOLOCK for a table, but now for the index?
Or some other clever trick (other than dropping the index or using a clustered index)?
Looking forward to some smart solutions :-)