In this article series, we will find basics and common usage scenarios about the inline table-valued functions and we will also be consolidating your learnings with practical examples.
在本系列文章中,我们将找到有关内联表值函数的基础知识和常见用法场景,并且还将通过实际示例巩固您的学习经验。
- Note: To learn more about multi-statement table-valued functions, please refer to the 注意:要了解有关多语句表值函数的更多信息,请参阅SQL Server multi-statement table-valued functions articleSQL Server多语句表值函数文章
At first, we will briefly look for an answer to the “Why should we use functions in the SQL Server?” question.
首先,我们将简要寻找“为什么要在SQL Server中使用函数?”的答案。 题。
In the SQL Server database development process, functions allow us to wrap up the codes in a single database executable database object. In other words, functions allow applying the encapsulation idea to T-SQL codes. So, a written function can be reused multiple times. In this way, we don’t spend time writing the same code over and over again and as a result, we can reduce the repetition of code. Additionally, the SQL Server function usage helps to degrade the code clutter.
在SQL Server数据库开发过程中,函数使我们可以将代码包装在单个数据库可执行数据库对象中。 换句话说,函数允许将封装思想应用于T-SQL代码。 因此,编写的函数可以多次重用。 这样,我们就不必花时间一遍又一遍地编写相同的代码,因此,我们可以减少代码的重复。 此外,SQL Server函数的用法有助于降低代码混乱度。
描述 ( Description )
The simple definition of the table-valued function (TVF) can be made such like that; a user-defined function that returns a table data type and also it can accept parameters. TVFs can be used after the FROM clause in the SELECT statements so that we can use them just like a table in the queries.The first thing that comes to our mind is that, what is the main difference between the view (Views are virtual database objects that retrieve data from one or more tables) and TVF? The views do not allow parameterized usage this is the essential difference between views and TVFs. In the following sections, we will reinforce these theoretical pieces of information with practical examples from easy to the difficult. The TVFs can be categorized into two types. These are inline and multi-statement table-valued functions. In this article, we particularly focus on the inline one.
可以像这样对表值函数 ( TVF )进行简单定义; 用户定义的函数,它返回表数据类型,并且可以接受参数。 TVFs后可以在FROM子句中的SELECT语句,这样我们就可以使用它们就像是涉及到我们的脑海中查询。第一个事情表是被使用,有什么看法之间的主要区别( 视图是虚拟数据库对象从一个或多个表中检索数据)和TVF ? 视图不允许参数化使用,这是视图和TVF之间的本质区别。 在以下各节中,我们将通过从易到难的实际示例来加强这些理论信息。 TVF可以分为两种类型。 这些是内联和多语句 表值函数 。 在本文中,我们特别关注内联代码。
You can direct to this article,