Day 20. User-Defined Functions in SQL

In every programming language, there is a group of prewritten routines that can be used by anyone using the language. These routines are called built-in functions. During most of this book, you have used or have seen many of the functions available to you when coding T-SQL scripts. However, there probably will be many times when these functions do not supply the functionality you need.

When you start writing complex T-SQL applications, you will find that many of the actions and calculations that you perform are repetitive. Of course, you could decide to use stored procedures to perform some of these tasks, but you might also want to consider creating your own functions so that you can then use them elsewhere in the application.

Microsoft SQL Server 2000 provides a powerful new feature that enables you to define your own reusable functions, which are called user-defined functions or UDFs. In today's lesson, I will cover the following topics:

  • Creating a user-defined function

  • Using a UDF in views and queries

  • Returning a table data type

  • Handling errors

  • Performance and the UDF

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset