Search code examples
sql-server-2008sql-server-2005insert-updatedatabase-deadlocksrowlocking

Update - Select on same table creating deadlock


I am finding it difficult to find solution for this deadlock. The select query is taking shared lock over index I_SEM_AGENT_COMPUTER_ID_PLUS, at the same time update query updates a record (say r1) in table and then tries to update the index I_SEM_AGENT_COMPUTER_ID_PLUS (this index has columns in include clause that are updated by update query ) However select is requesting record r1 in shared mode. What can be possible solution to this? Apart from creating a new non-clustered index for select. Note: Dirty reads not allowed, READPAST can't be used as this can return no records failing purpose of select here


Solution

  • Finally solved this problem, rearranged both the queries to access the resources in the same order. That solved the problem.