SQL Server 2012 - How does “Repeatable Read” isolation level work?

会有一股神秘感。 提交于 2021-01-27 10:42:01

问题


I feel like I should know this, but I can't find anything that specifically outlines this, so here goes.

The documentation for SQL Server describes REPEATABLE READ as:

Specifies that statements cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes

This makes sense, but what actually happens when one of these situation arises? If, for example, Transaction A reads row 1, and then Transaction B attempts to update row 1, what happens? Does Transaction B wait until Transaction A has finished and then try again? Or is an exception thrown?


回答1:


REPEATABLE READ takes S-locks on all rows that have been read by query plan operators for the duration of the transaction. The answer to your question follows from that:

  1. If the read comes first it S-locks the row and the write must wait.
  2. If the write comes first the S-lock waits for the write to commit.

Under Hekaton it works differently because there are no locks.



来源:https://stackoverflow.com/questions/30238059/sql-server-2012-how-does-repeatable-read-isolation-level-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!