开发者

Indexed Views And Scalar UDFs

Can UDFs be used inside index views or does this break the SCHEMABINDING logic?

For example if in the where clause of the view I had something like this

WHERE
     UserCanSeePost(UserId,PostId)

This UDF would then do a lookup on another table to check some res开发者_StackOverflowtrictions. I'm guessing this cant be done in indexed views?


Yes, if it's deterministic and itself has SCHEMABINDING

See Indexed views too:

...
User-defined functions referenced in the view must have been created with the SCHEMABINDING option.
...
All functions referenced by expressions in the view must be deterministic. The IsDeterministic property of the OBJECTPROPERTY function reports whether a user-defined function is deterministic. For more information, see Deterministic and Nondeterministic Functions.
...


If the function is created WITH SCHEMABINDING, then you can use WITH SCHEMABINDING on a view built on top of it. I'm not 100% sure, but I think functions WITH SCHEMABINDING were introduced in SQL Server 2005...

Edit -> Nope, apparently you could use WITH SCHEMABINDING in 2000 as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜