I have a simple application.This application update data of a table (B) from another table(A) which is changed every 60 sec. User may read data at any time so creating deadlock. How is this sort of problem solved in real world. Considering maximum 100 users how could I avoid deadlock. How would web application handling thousand of request avoid deadlock?


Select Query : Select * from tableB
Update Query : update table tableB set tableB.someCOl = tableA.someCol where tableA.col1 = tableB.col3

enter image description here


2 Answers 2


The simplest way to reduce deadlocks - proper indexing. Make sure, that client's read requests not involving table/clustered index scans - if any - this is the open gates to deadlocks

And make sure, that your index has its allow_page_lock and allow_row_lock options ON


A deadlock involves two resources accessed in different order by different processes. For example:

  • Process 1 reads from table A and then updates table B
  • Process 2 reads from table B and then updates table A

This generates a deadlock when both processes are halfway done. Process 1 has a lock on table A and waits for a lock on table B, and process 2 has a lock on table B and waits for a lock on table A. SQL Server resolves this situation by killing one of the two processes and logging a deadlock event.

But in the situation you describe there is only one shared resource, table B. That is unlikely to generate a deadlock. When the update begins, existing reads will complete but future reads are put on hold. The future reads won't deadlock but wait.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.