MS SQL Maestro online Help
UDFs
A user-defined function (UDF) is stored as a database object providing reusable code that can be used in Transact-SQL (T-SQL) statements such as SELECT, in applications calling the function, in the definition of another user-defined function, to parameterize a view or improve the functionality of an indexed view, to define a column in a table, to define a CHECK constraint for a column or to replace a stored procedure.
User-defined functions have been expanded in Microsoft SQL Server 2005 to include functions written in any .NET programming language. SQL Anywhere allows to define user-specific database functions. In an SQL statement, you can then use these user-defined database functions in the same way as any other predefined functions.
New UDFs are created within Create UDF Wizard. In order to run the wizard you should either
• | select the Object | Create Database Object... main menu item; |
• | select the UDF icon in the Create Database Object dialog |
or
• | select the UDFs list or any object from that list in the explorer tree; |
• | select the Create New UDF... item from the popup menu |
or
• | open Database Editor, or (for Microsoft server 2005) Schema Editor and the UDFs tab there; |
• | press the Insert key or select the Create New UDF item from the popup menu (alternatively, you may use the corresponding link of the Navigation Bar). |
To create a new UDF with the same properties as one of the existing UDFs has:
• | select the Object | Duplicate Database Object... main menu item; |
• | follow the instructions of Duplicate Object Wizard. |
|
UDFs can be edited within UDFEditor. In order to open the editor you should either
• | select the UDF for editing in the explorer tree (type the first letters of the UDF name for quick search); |
• | select the Edit UDF item from the popup menu |
or
• | open Schema Editor and the UDFs tab there; |
• | press the Enter key or select the Edit UDF item from the popup menu (alternatively, you may use the corresponding link of the Navigation Bar). |
You can change the name of the UDF using the Rename UDF dialog:
• | select the UDF to rename in the explorer tree; |
• | select the Rename UDF item from the popup menu. |
|
To execute the UDF:
• | select the UDF in the explorer tree (type the first letters of the UDF name for quick search); |
• | select the Edit UDF... item from the popup menu; |
• | execute the UDF using the Execute link of the Navigation Bar |
or
• | open Schema Editor and the UDFs tab there; |
• | select the UDF to execute; |
• | press the Enter key or select the Edit UDF item from the popup menu, or use the corresponding link of the Navigation Bar; |
• | execute the UDF using the Execute link of the Navigation bar. |
|
To drop a UDF:
• | select the UDF to drop in the explorer tree; |
• | select the Drop UDF item from the popup menu |
or
• | open Schema Editor and the UDFs tab there; |
• | press the Delete key or select the Drop UDF item from the popup menu (alternatively, you may use the corresponding link of the Navigation Bar) |
and confirm dropping in the dialog window.
|