SQL Server 视图还是表值函数?
有人有一个好的决策树来决定何时使用视图以及何时使用 SQL Server 中的表值函数吗?
Anyone have a good decisioning tree for deciding when to use a view and when to use a table-valued function in SQL Server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尽管任何视图几乎都可以轻松地转换为内联表值函数,但反之则不然。
如果需要对构造进行参数化,则使用内联表值函数。内联表值函数基本上是参数化视图,因为优化器能够将它们与视图结合起来并推动事物。多语句表值函数与内联表值函数完全不同。
如果无法使用内联表值函数来完成此操作,请使用多语句表值函数。
Although any view can almost trivially be converted to an inline table-valued function, the converse is not true.
If the construct needs to be parametrized, then use an inline table-valued function. Inline table-value functions are basically parametrized views in terms of the optimizer being able to combine them with views and push things around. Multi-statement table-valued functions are not at all like inline table-valued functions.
If you cannot do it with an inline table-valued function, use a multi-statement table-valued function.
有些事情你不能在视图中执行(例如表变量、返回结果集之前的中间结果等)...如果你不需要这些,请查看,如果需要,则sproc/udf :-)
There's certain things you can't do in a view (such as table variables, intermediate results before you return your result-set, etc.) ... if you don't need those, view, if you do, sproc/udf :-)
好吧,我会给出我们所做的用途。我们有表,但我们从不访问表,而是访问有关表的视图。这只是一个安全问题。
Ok, I'll give the use we do. We have the tables, but we never access the tables, but the views about the tables. It's just a security issue.