A table-valued function is a function that returns a table instead of a single value.
Database Explorer lets you perform operations on table-valued functions using the shortcut menu. Right-click a function in Database Explorer to access options for tasks such as creating, managing, or debugging functions. You can also generate scripts for them.
1. In Database Explorer, right-click a table-valued function or Table-valued Functions node and select New Table-valued Function.
2. In a SQL document, fill in the CREATE FUNCTION statement template.
3. At the bottom of the SQL document, click Apply Changes.
You can edit a function in one of these ways.
1. In Database Explorer, right-click the table-valued function you want to edit and select Modify via SQL.
2. In a SQL document, edit the function.
3. In the top menu, select File > Save or press Ctrl+S.
1. In Database Explorer, right-click the table-valued function you want to edit and select Open Editor.
2. In a SQL document, edit the function.
3. At the bottom of the SQL document, click Apply Changes.
Alternatively, in the top menu, select File > Save or press Ctrl+S.
1. In Database Explorer, right-click the table-valued function you want to delete and select Delete, or press Delete.
2. Click Yes to confirm the deletion.
Note
You cannot undo the drop function operation, as this action permanently deletes all its data and structure. It is recommended that you back up the database before deleting it.
1. In Database Explorer, right-click the table-valued function you want to execute and select Execute.
2. In the View output parameters dialog, enter the parameters.
3. Click Close.
To start debugging a table-valued function, in Database Explorer, select Step Into from the shortcut menu and follow the steps from How to debug a function.
1. In Database Explorer, right-click a required table-valued function and select Duplicate Object.
2. In the Duplicate Object dialog, configure the object settings:
3. Click OK.
1. In Database Explorer, right-click a required table-valued function and select Generate Script As, then select the statement type.
2. Select the output option:
For more information, see Generate the DDL and DML statements for database objects.
To add a table-valued function to the database diagram, in Database Explorer, right-click a required table-valued function and select Send To > Database Diagram.
To view function properties, in Database Explorer, right-click the table-valued function or Table-valued Functions node and select Show Details.
Object Viewer opens, displaying detailed information about the table-valued function.
To update the table-valued function to reflect the latest changes, in Database Explorer, right-click the table-valued function or Table-valued Functions node and select Refresh, or press F5.
To open the Properties window, in Database Explorer, right-click the table-valued function and select Properties, or press F4.
1. In Database Explorer, right-click the Table-valued Functions node and select Filter.
2. In the Filter Settings dialog, configure the filter parameters.
3. Click OK to apply the filter.
Note
When you open the Table-valued Functions node, the number of objects it contains appears in parentheses next to the node name. This number changes based on your filter settings.
The following table describes the shortcut menu options, which appear when you right-click a specific table-valued function in Database Explorer.
| Name | Description |
|---|---|
| New Table-valued Function | Opens a CREATE FUNCTION template in a new SQL document to create a table-valued function. |
| Modify via SQL | Opens the existing function in a new SQL document containing an ALTER FUNCTION statement to update it. |
| Open Editor | Opens the selected function in a new SQL document containing a CREATE FUNCTION statement to create the function or change its code. |
| Execute | Executes the function. |
| Step Into | Starts debugging the function. Shortcut: F11 |
| Duplicate Object | Opens the Duplicate Object dialog to duplicate the function. |
| Generate Script As | Generates a script of the selected object using the CREATE, CREATE OR ALTER, DROP, DROP and CREATE, ALTER, and SELECT statements. The script can be saved to a new SQL document or to a file, or copied to the clipboard. |
| Send to > Database Diagram | Adds the selected function to a database diagram. |
| Show Details | Opens Object Viewer to view object details. |
| Delete | Drops the selected function from the database. Shortcut: Delete |
| Refresh | Updates the object to reflect the latest changes. Shortcut: F5 |
| Properties | Opens the Properties pane to view the object information. Shortcut: F4 |
The following table describes the shortcut menu options, which appear when you right-click the Table-valued Functions node in Database Explorer.
| Name | Description |
|---|---|
| New Table-valued Function | Opens a new SQL document containing the CREATE FUNCTION statement. |
| Filter | Opens the Filter Settings dialog to control which table-valued functions should appear in Database Explorer. |
| Show Details | Opens Object Viewer to view object details. |
| Refresh | Updates the object to reflect the latest changes. Shortcut: F5 |