Creating a Function
Functions return the results of a specific action quickly. This section describes how to create a function.
To create functions, you need to obtain the CREATE ROUTINE permission. To alter and drop functions, you need the ALTER ROUTINE permission.
You have obtained the login permission and logged in to the database management page.
There are three types of functions supported in Microsoft SQL Server: inline table-valued function, multi-statement table-valued function, and scalar-valued function. This following uses the inline table-valued function as an example to describe how to create a function.
- Table value functions can be inline table-valued functions or multi-statement table-valued functions. You can use the table-valued function templates to create functions.
- Scalar-valued functions can be created by using a scalar-value function template.
- System functions can only be viewed and cannot be edited.
- In the navigation tree on the left, right-click Functions under the target database and choose Create Function > Inline Table-valued Function from the shortcut menu.
- On the page for editing a function, click Set Template Parameter. In the displayed dialog box, set required parameters and click OK.
- Click Save.
- Click Execute. In the displayed dialog box, set required parameters and click Execute.
- View the result.