标签:
with(nolock)是微软推荐使用的table hint,用于代替(nolock),使用with(nolock)是强制sql 引擎不要对数据加锁,提高查询的速度,但是有可能出现dirty data。
当这两个table hint用于cte时,会出现不同的结果,以下代码使用with(nolock),sql 引擎能够正常识别和执行
;with cte as
(
select * from dbo.test with(nolock)
)
select *
from cte with(nolock)
如果将with(nolock)替换成(nolock),将会出错,错误信息是:
Msg 215, Level 16, State 1, Line 7
Parameters supplied for object ‘cte‘ which is not a function. If the parameters are intended as a table hint, a WITH keyword is required.
错误原因是sql 引擎将 cte(nolock) 看作是一个函数,而该函数并没有注册,所以sql 引擎无法识别,在使用table hint的时候,使用微软推荐的方式,加上with,避免出错。
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/4546081.html