SQL Server视图还是表值函数? [重复]

时间:2022-02-16 01:28:00

This question already has an answer here:

这个问题在这里已有答案:

Anyone have a good decisioning tree for deciding when to use a view and when to use a table-valued function in SQL Server?

任何人都有一个很好的决策树来决定何时使用视图以及何时在SQL Server中使用表值函数?

3 个解决方案

#1


13  

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.

如果使用内联表值函数无法执行此操作,请使用多语句表值函数。

#2


2  

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 :-)

在视图中你不能做某些事情(例如表变量,返回结果集之前的中间结果等)...如果你不需要那些,查看,如果你这样做,sproc / udf :-)

#3


-1  

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.

好的,我会给我们用的。我们有表,但我们从不访问表,而是关于表的视图。这只是一个安全问题。

#1


13  

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.

如果使用内联表值函数无法执行此操作,请使用多语句表值函数。

#2


2  

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 :-)

在视图中你不能做某些事情(例如表变量,返回结果集之前的中间结果等)...如果你不需要那些,查看,如果你这样做,sproc / udf :-)

#3


-1  

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.

好的,我会给我们用的。我们有表,但我们从不访问表,而是关于表的视图。这只是一个安全问题。