SQL Server - 如何将(nolock)提示设置为默认值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1035740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server - how to set (nolock) hint as a default?
提问by opensas
is there some way to tell sql server to use the (nolock) hint or every select in a stored procedure?
有什么方法可以告诉 sql server 在存储过程中使用(nolock)提示或每个选择?
is pretty tiresome to add it to each an every select....
将它添加到每个选择中是很烦人的....
采纳答案by opensas
found this....
发现这个....
How to force nolock hint for sql server logins
seems like the best way to achieve this is to issue a
似乎实现这一目标的最佳方法是发出
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
设置事务隔离级别读取未提交
any other idea???
还有其他想法吗???
ps
ps
another related question...
另一个相关问题...
回答by Robin Day
As others quite rightly say, a global (nolock) is done using READ UNCOMMITTED.
正如其他人所说的那样,全局(nolock)是使用 READ UNCOMMITTED 完成的。
However, before going down that route, it's worth trying READ COMMITTED SNAPSHOT first. This means your reads won't be locked by in progress inserts / updates and means that the data isn't dirty, just out of date.
但是,在走这条路线之前,值得先尝试 READ COMMITTED SNAPSHOT。这意味着您的读取不会被正在进行的插入/更新锁定,并且意味着数据不是脏的,只是过时了。
回答by Dan Wolchonok
You want to use the following syntax:
您想使用以下语法:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
设置事务隔离级别读取未提交
I found this by looking at the NOLOCK table hint located here. The WITH(NOLOCK) table hint is equivalent to setting the isolation level to be READ UNCOMMITTED. Here's the snippet from MSDN:
我通过查看位于此处的 NOLOCK 表提示发现了这一点。WITH(NOLOCK) 表提示相当于将隔离级别设置为 READ UNCOMMITTED。这是来自MSDN的片段:
NOLOCK Is equivalent to READUNCOMMITTED. For more information, see READUNCOMMITTED later in this topic.
NOLOCK 相当于 READUNCOMMITTED。有关更多信息,请参阅本主题后面的 READUNCOMMITTED。
回答by bytebender
I think this is what you are looking for...
我想这就是你要找的...
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
设置事务隔离级别读取未提交
回答by A-K
However, you may end up with incorrect data. On 2005, it is preferable to use snapshot isolation: "When Snapshot Isolation Helps and When It Hurts" http://www.devx.com/dbzone/Article/32957
但是,您最终可能会得到不正确的数据。在 2005 年,最好使用快照隔离:“当快照隔离有帮助时,它会受到伤害” http://www.devx.com/dbzone/Article/32957