可重复读取 - 我理解对吗?
尝试完全理解 SQL Server 隔离级别 - 特别是可重复读取。
我有一个存储过程,它启动一个事务并将光标放在一些数据上(嘘声)。这可能是相当大的数据块,因此可能需要一段时间才能完成。
然后它将提交或回滚。
在此期间,在事务关闭之前,如果有人调用导致某些受影响的行被读取的方法,我的理解是该方法将停止,直到第一个方法完成。然后他们将获得数据(只要首先没有发生超时)
我认为我是对的,但问题是 - 我是吗?
Trying to completely understand SQL Server Isolation Levels - notably REPEATABLE READ.
I have a sproc that starts a transaction and puts a cursor around some data (boo hiss). This can be a fair chunk of data, so can take a while to do.
It will then COMMIT or ROLLBACK.
During this time, before the transaction has been closed, if someone calls a method which causes some of those affected rows to be READ, my understanding is that this method will stall until the first method is complete. They will then be served up the data (as long as a time-out doesn't occur first)
I think I'm right, but question is - am I?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
REPEATABLE READ
会阻止SELECT
解除它们放置的共享锁,直至事务结束。将事务
1
设置为READ COMMITTED
,在事务2
中选择行后,您可以更新事务2
中的行<代码>1。如果事务
1
为REPEATABLE READ
,则在事务2
中选择行后,您无法更新事务2
中的行<代码>1。场景:
READ COMMITTED
REPEATABLE READ
更新:
至于你的问题:在
SQL Server
中,SELECTs
即使使用也不会互相锁定可重复读取,因为它们放置的共享锁彼此兼容:
REPEATABLE READ
preventsSELECTs
from lifting shared locks they placed until the end of the transaction.With transaction
1
asREAD COMMITTED
, you can update a row in transaction2
after you selected it in transaction1
.With transaction
1
asREPEATABLE READ
, you cannot update a row in transaction2
after you selected it in transaction1
.The scenarios:
READ COMMITTED
REPEATABLE READ
Update:
As for you question: in
SQL Server
,SELECTs
will not lock each other even withREPEATABLE READ
, since shared locks they place are compatible with each other:正确的。
来自 MSDN 的完整说明:
Correct.
A full description from MSDN: