User-defined functions in SQL Server

Source: Internet
Author: User

User-defined functions in SQL Server

User-Defined Functions (UDF: User Defined Functions:

Similar to stored procedures, user-defined functions are a set of ordered T-SQL statements, udfs are pre-optimized and compiled and can be debugged as a unit. The main difference between a UDF and a stored procedure is the way the result is returned. To support multiple different return values, UDF has more restrictions than stored procedures.

Two types of UDF:

1. Return the scalar value UDF

2. Return the UDF of the table

Function certainty:

Certainty means that the returned result is definite. or, if the same function is used without any changes, the returned value will not change under the same conditions.

Udfs can be deterministic or non-deterministic.

When a UDF needs to meet the requirements of certainty, the following four conditions must be met:

1. The function must be bound in the mode. This means that any object the function depends on will have a dependency record, and this object cannot be changed before the dependent function is deleted.

2. All other functions referenced by a function, whether user-defined or system-defined, must be determined.

3. Tables defined outside the function cannot be referenced (Table variables and temporary tables can be used as long as they are defined within the function scope ).

4. You cannot use extended stored procedures.

Function certainty check:

Select objectproperty (Object_id ('function name'), 'isterministic ');




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.