Can a readcommitted isolation level ever result in a deadlock (Sql Server)?

前端 未结 2 1022
栀梦
栀梦 2021-02-14 04:55

My understanding of deadlocks is - two processes trying to contend for same resource - typically two processes trying to \'write\' to same row of data. If all one process is doi

2条回答
  •  礼貌的吻别
    2021-02-14 05:32

    Yes, it can happen. Imagine you have two processes each with its own transaction. The first updates TableA then tries to update TableB. The second updates TableB then tries to update TableA. If you're unlucky, both processes manage to complete their first step and then wait indefinitely to the other in order to complete the second step.

    Incidentally, that's one of the most common ways to avoid deadlocks: be consistent in order in which you update your table. If both processes updated TableA first then TableB, the deadlock wouldn't occur.

提交回复
热议问题