gpt4 book ai didi

sql - 在使用 View 的查询中使用WITH NOLOCK 表提示 - 它是否在 View 内传播?

转载 作者:行者123 更新时间:2023-12-02 09:34:01 37 4
gpt4 key购买 nike

如果在 SQL Server 中的 View 上使用“WITH NOLOCK”查询提示,即使 View 定义中的原始表未使用 NOLOCK,它是否会将该提示传播到 View 定义本身?需要这样做的原因是,有时支持人员想要执行大量耗时的查询,但又不想使用应用程序本身的 View 对所有查询强制锁定。

最佳答案

是的,NOLOCK 将传播到 View 定义所使用的表(至少在 SQL Server 2005 中)。

参见Table Hints在 MSDN 中:

In SQL Server 2005, all lock hints are propagated to all the tables and views that are referenced in a view. Also, SQL Server performs the corresponding lock consistency checks.

但是,

If a table contains computed columns and the computed columns are computed by expressions or functions accessing columns in other tables, the table hints are not used on those tables. This means the table hints are not propagated. For example, a NOLOCK table hint is specified on a table in the query. This table has computed columns that are computed by a combination of expressions and functions that access columns in another table. The tables referenced by the expressions and functions do not use the NOLOCK table hint when accessed.

如果您使用索引 View ,您可能需要阅读更多内容,因为也有一些特殊情况。

另请参阅View Resolution了解更多信息。

关于sql - 在使用 View 的查询中使用WITH NOLOCK 表提示 - 它是否在 View 内传播?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/981671/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com