什么是“with (nolock)"?在 SQL Server 中? [英] What is "with (nolock)" in SQL Server?

查看:36
本文介绍了什么是“with (nolock)"?在 SQL Server 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释在查询中使用 with (nolock) 的含义,什么时候应该/不应该使用它?

Can someone explain the implications of using with (nolock) on queries, when you should/shouldn't use it?

例如,如果您的银行应用程序具有高交易率且某些表中有大量数据,那么 nolock 可以使用哪些类型的查询?是否存在您应该始终使用它/从不使用它的情况?

For example, if you have a banking application with high transaction rates and a lot of data in certain tables, in what types of queries would nolock be okay? Are there cases when you should always use it/never use it?

推荐答案

WITH (NOLOCK) 相当于使用 READ UNCOMMITED 作为事务隔离级别.因此,您面临着读取随后回滚的未提交行的风险,即从未进入数据库的数据.因此,虽然它可以防止读取被其他操作造成死锁,但它带来了风险.在具有高交易率的银行应用程序中,恕我直言,它可能不是您试图用它解决的任何问题的正确解决方案.

WITH (NOLOCK) is the equivalent of using READ UNCOMMITED as a transaction isolation level. So, you stand the risk of reading an uncommitted row that is subsequently rolled back, i.e. data that never made it into the database. So, while it can prevent reads being deadlocked by other operations, it comes with a risk. In a banking application with high transaction rates, it's probably not going to be the right solution to whatever problem you're trying to solve with it IMHO.

这篇关于什么是“with (nolock)"?在 SQL Server 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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