WITH (NOLOCK) vs SET 事务隔离级别读取未提交 [英] WITH (NOLOCK) vs SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

查看:48
本文介绍了WITH (NOLOCK) vs SET 事务隔离级别读取未提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指导我什么时候使用 WITH (NOLOCK) 而不是 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

Could someone give me some guidance on when I should use WITH (NOLOCK) as opposed to SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

各自的优缺点是什么?使用一种而不是另一种,您是否遇到过任何意外后果?

What are the pros/cons of each? Are there any unintended consequences you've run into using one as opposed to the other?

推荐答案

它们是一回事.如果您使用set transaction isolation level 语句,它将应用于连接中的所有表,因此如果您只想在一个或两个表上使用nolock,请使用它;否则使用另一个.

They are the same thing. If you use the set transaction isolation level statement, it will apply to all the tables in the connection, so if you only want a nolock on one or two tables use that; otherwise use the other.

两者都会给你带来脏读.如果您对此感到满意,请使用它们.如果你不能有脏读,那么可以考虑 snapshotserializable 提示.

Both will give you dirty reads. If you are okay with that, then use them. If you can't have dirty reads, then consider snapshot or serializable hints instead.

这篇关于WITH (NOLOCK) vs SET 事务隔离级别读取未提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆