Implement User-defined Functions in SQL Server 2005 with Managed Code

Thursday Aug 26th 2004 by Staff

Discover how you can use C# and the .NET CLR to create user-defined functions for tapping directly into SQL Server 2005.


One of the excellent features of SQL Server 2005 is its integration with the .NET common language runtime (CLR), which extends SQL Server's capability in several important ways. The integration enables developers to create database objects such as stored procedures, user-defined functions, and triggers by using modern object-oriented languages such as VB.NET and C#. This article explains how to create user-defined functions using C#. It then tests the user-defined function using the SQL Server integration features of Visual Studio 2005. Finally, it creates a Windows Forms client application to test the user-defined function.


Although Transact-SQL (T-SQL), the existing data-access and manipulation language, is well suited for set-oriented, data-access operations, it also has limitations. Microsoft designed it more than a decade ago, and it is a procedural language rather than an object-oriented language. The integration of the .NET CLR with SQL Server enables the development of stored procedures, user-defined functions, triggers, aggregates, and user-defined types using any of the .NET languages. The SQL Server engine hosts the CLR in process. All managed code that executes in the server runs within the confines of the CLR. The managed code accesses the database using ADO.NET and the new SQL Server .NET Data Provider.

The article continues at

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved