NOLOCK 与事务隔离级别
使用“SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED”和NOLOCK有什么区别? 这个比那个好吗?
What's the difference between using "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" and NOLOCK? Is one better than the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它们是同一件事,只是范围不同。 NOLOCK 是基于每个表放置的,
SET Transaction...
可以放置为一个块。They're the same thing, just scoped differently. NOLOCK is placed on a per table basis and
SET Transaction...
can be placed as a block.NOLOCK 是一个查询提示,因此仅适用于指定它的查询中的特定表。
设置事务隔离级别适用于当前连接内此后执行的所有代码或直到显式修改为止。
需要澄清的是,从功能上讲,工作中的隔离级别是相同的,但涵盖的范围可能不同。
NOLOCK is a query hint and as such only applies to the specifc table within the query in which it is specified.
Setting the transaction isolation level applies to all code executed hence forth within the current connection or until it is explicitly modified.
To clarify, functionally the isoloation level at work is the same however the scope which is covered may not be.
请参阅几个小时前针对该问题的该答案 SQL Server SELECT 语句导致阻塞。
引用 Remus Rusanu:
其他答案也可能对您有帮助。
See that answer from a few hours ago, to the question SQL Server SELECT statements causing blocking.
Quoting Remus Rusanu:
The other answers may help you as well.
它们具有相同的效果,只有一个用作锁定提示(nolock),另一个用于连接范围。
请小心其中任何一个 - 脏读可能是一件非常糟糕的事情,具体取决于您的应用程序。 两次读取同一条记录或由于页面移动而丢失一条记录对于用户来说可能是一件非常令人困惑的事情......
They have the same effect, only one is used as a lock hint (nolock) and the other is used for a connection scope.
Be careful with either of those - dirty reads can be a very bad thing depending on your app. Reading the same record twice or missing a record because of page movement can be a very confusing thing to users...