SQL Server多语句表值函数

In this article, we will learn multi-statement table-valued functions (MSTVFs) basics and then we will reinforce our learnings with case scenarios.

在本文中,我们将学习多语句表值函数(MSTVF)的基础知识,然后我们将通过案例场景来加强学习。

At first, If you are a newbie about the SQL Server functions concept, I would suggest taking a glance at the following two articles before to start this one:

刚开始时,如果您是有关SQL Server函数概念的新手,建议您在开始本文之前先阅读以下两篇文章:

  1. How to use SQL Server built-in functions and create user-defined scalar functions 如何使用SQL Server内置函数和创建用户定义的标量函数
  2. SQL Server inline table-valued functions SQL Server内联表值函数

我们为什么使用这些功能 (Why we use the functions)

With the help of the functions, we can encapsulate the codes and we can also equip and execute these code packages with parameters.

借助这些功能,我们可以封装代码,还可以为参数代码装备并执行这些代码包。

Don’t Repeat Yourself (DRY) is a software development approach which advises that “as much as possible, don’t rewrite the same code again”. The main idea of this approach is to reduce code repetition. The main advantages of this idea are:

不要重复自己( DRY )是一种软件开发方法,建议“尽可能,不要再重写相同的代码”。 这种方法的主要思想是减少代码重复。 这个想法的主要优点是:

  • Improve maintainability

    改善可维护性
  • Improve the code readability

    提高代码可读性

If we want to gain these benefits in SQL Server, the user-defined functions come at the first point in the list in order to implement this idea.

如果我们想在SQL Server中获得这些好处,则用户定义的函数位于列表的第一位,以实现这一思想。

In the following section, we will go through with MSTVFs basics and usage scenarios.

在下一节中,我们将介绍MSTVF的基础知识和使用场景。

说明和语法: (Description and syntax:)

Multi-statement table-valued function returns a table as output and this output table structure can be defined by the user. MSTVFs can contain only one statement or more than one statement. Also, we can modify and aggregate the output table in the function body. The syntax

你可能感兴趣的:(数据库,python,java,mysql,人工智能)