Working with User Defined Functions


Functions are subroutines made up of one or more Transact-SQL statements that can be used to encapsulate code for reuse. Microsoft SQL Server 2000 does not limit users to the built-in functions defined as part of the Transact-SQL language, but allows users to create their own user-defined functions.

User-defined functions cannot be used to perform a set of actions that modify the global database state. User-defined functions, like system functions, can be invoked from a query. They also can be executed through an EXECUTE statement like stored procedures.

 

Adding a New User Defined Function

 

To add a new user defined function, you can:

 

Then enter a name in the Enter User Defined Function Name dialog box. Click on the OK button on the dialog box. The Edit User Defined Function dialog appears (see Figure 2).

 

Figure 1  Enter User Defined Function name dialog


Editing a User Defined Function

 

To edit a user defined function, you can:

 

Figure 2  Edit User Defined Function Dialog

 

When the Edit User Defined Function dialog appears, you can modify the script of the User Defined Function in the window. Chick on the Check Syntax button to check the script syntax you have entered. If there is no error in syntax, click on the Save button will save the script to the SQL Server database.

 

Deleting a User Defined Function


To delete a user defined function, you can:

 

It will delete the selected user defined function.

 

Renaming a User Defined Function


This operation allows you to rename a user-defined function.

 


SQLSourceSafe, 2003-2006 © Copyright, Best SoftTool, Incorporated