.NET CLR Programming with SQL Server 2005 Made Simple
(Page 1 of 6 )
This article explains how to create .NET based CLR sub-routines in SQL Server 2005 in the simplest way possible. It is mainly targeted at .NET developers who want to work with SQL Server 2005 at server side.
A downloadable file for this article is available
here.
The following are the topics covered in this article:
- Creating a new database, table and a few rows.
- Creating, coding and testing a .NET CLR stored procedure.
- Creating, coding and testing a .NET CLR user-defined function.
- Creating, coding and testing a .NET CLR aggregate function.
The entire source code for this contribution is freely available for download.
Creating your own database in SQL Server 2005
This section mainly covers the creation of a database and tables to be used in this series. Go through the following steps:
- Go to Start -> Programs -> Microsoft SQL Server 2005 -> SQL Server Management Studio and connect to your SQL Server 2005 instance with the necessary credentials.
- Once connected, open the SQL Server 2005 instance using the “Object Explorer," right click on “databases” and select “New Database” (Fig 1).

You will be presented with the “New Database” dialog. Provide the database name “Sample” and click on “OK” to create the new database within the same instance.
- Once the database is created, you must be able to watch the same in “Object explorer.”
- Using the “Object explorer,” open “Sample” database, right click on “tables” and select “new table" (Fig. 2).
- Create the structure of the table as shown in the following figure
(Fig 3) and save the table with the name “emp.”

- Once you have created the table “emp,” open it (Fig 4) and fill with rows as shown (Fig 5).

Next: .NET CLR stored procedure in SQL Server 2005 database: creation >>
More MS SQL Server Articles
More By Jagadish Chaterjee