Summary of the understanding of functions in SQL Server

Source: Internet
Author: User
Tags sql server tutorial

T-SQL language provides us with a more flexible way to manipulate data, that is, functions, functions are divided into three main categories: scalar function: (pass in a parameter, and then a parameter) aggregate function (pass in multiple parameters, outgoing one parameter), table-valued function (passing in a result set object, So that we can manipulate the table by manipulating it, the table-valued functions are subdivided into two categories: inline table-valued functions and multi-statement table-valued functions. The inline table-valued function looks like this:

1 CREATE FUNCTION my_fun ()RETURNSTABLE2as3     RETURN 4         SELECT *  from Table_1

The error-prone detail of writing functions is the difference between returns and return

The above is the inline table-valued function, and then look at the multi-statement table-valued Function:

The difference between an inline table-valued function and a multi-statement table-valued function is indicated in the textbook:

The inline table-valued function does not have a function subject (Begin-end) that returns the result set of a single select, whereas a multi-statement table-valued function is composed of multiple T-SQL statement sequences between Begin-end, which can generate record rows and insert rows into a table, and then return a table. ----The third edition of SQL Server tutorial

The following is an example of a multi-statement table-valued Function:

CREATE FUNCTION myfun_2 ()RETURNS@my_list(      char),       Char(ten)              )as    BEGIN           INSERT  @my_list-- operation    END

The function can add some modifiers to the value when it is passed, including read-only, default, and so on, similar to other languages.

Summary of the understanding of functions in SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.