he next version of SQL Server (code name Yukon) has extensive support for the Common Language Runtime (CLR).
Previous versions of SQL Server (2000 and earlier) had a mechanism for creating custom data types. These data types were nothing more than aliases to system data types. In Yukon, you can create your own fully functional custom data types.The process of creating a UDT begins with creating a .NET class that supports the proper API. Creating and using a UDT comes in two phases: creating the library and registering the UDT with SQL Server. The first step is to create your new data type in Visual Studio .NET. The listing for this article shows how to create a Social Security Number data type. When you create your UDT you will do the following:
- Create a new class library
- Import assembles
- Add two attributes to your class (Serializable() and SqlUserDefinedDataType)
- Implement the INullable interface
- Add required methods and properties to your class
- Compile your class
- Register your class library with SQL Server
Creating a Class Library
The initial phase of this process is to create a new class library. You create a new class by selecting New and then Project from the Visual Studio .NET menu. Select Class Library from either the C# or Visual Basic.NET (VB.NET) Projects list (this article demonstrates using VB.NET).
After creating your class library, you need to import the following assemblies
- System
- System.Data.SQL
- System.Data.SQLTypes
Adding Attributes
After adding the appropriate references, you need to “decorate” the class with two attributes. These attributes are Serializable() and SqlUserDefinedType. The Serializable attribute gives the CLR the ability to take the class and serialize it or to turn it into XML. SQL Server uses this capability to store and retrieve the class from its data store. The SqlUserDefineType attribute is used by SQL Server to determine how it should manage your class. This attribute has a number of properties. The two most important are Format and MaxByteSize. The Format property instructs SQL Server how to store the object. The MaxByteSize property determines how many bytes your data type can consume.
Implement the Object Interface
After decorating the class, you need to implement the .NET Framework INullable Interface. Interfaces are implemented using the Implements statement. The following snippet demonstrates how to implement the INullable interface.
Public ReadOnly Property _ IsNull() As Boolean Implements _ System.Data.SqlTypes_ .INullable.IsNull Get Return Me._IsNull End Get End Property
After implementing the INullable interface, you are required to implement the ToString() and Parse() methods and the Null() property
The ToString method is a common function found on most .NET classes. This function returns a representation of your data type as a string. Remember when you return the value from the ToString function you need to include a representation of NULL values. The following snippet shows the ToString method for this article’s example.
Public Overrides Function_ ToString() As String If Me.IsNull Then Return "NULL" Else Return Me._cInternalValue End If End Function
The other method that needs attention is the Parse() method. This is the method that SQL Server calls whenever someone inserts or updates data defined as your data type. The API for this method is as follows:
Parse(cData as SqlString) _ as
As you can see, this function receives a parameter declared as type SqlString. Upon receiving this code, you perform a number of tasks. The first task is to determine whether or not the data passed in is NULL. If it is, return Nothing from this method.
The second task is to convert the passed-in data to a .NET data type. This is done with the Convert class. After converting the passed-in data to a .NET data type, you can validate the data. If the data passed in does not conform to your rules, you can throw an exception. Figure 1 shows what an error thrown from a custom data type looks like.
![]() |
Registering the Class After you have created and compiled the class into a DLL, you need to go to SQL Server and perform two tasks.
The following SQL code demonstrates how to perform these tasks:
Using the Class
There are a couple of items to note from the above example. The first item is the use of the Cast() statement. In order to insert data into a custom data type, you need to cast the SQL Server data types into your own data types. The next item to note is the syntax for querying data from a custom data type. The syntax for querying data from a custom data type is As you can see, creating custom data types in SQL Server Yukon is pretty simple stuff. Finally, you can create your own “real” data types with validation rules and all. I hope you can see now how to take advantage of this feature with minimal effort. Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience. Related PostsAbout Our Editorial ProcessAt DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere. See our full editorial policy. ![]() Caching Strategies for High-Traffic Web Applications
Rashan Dixon
March 25, 2026
1:30 PM
![]() AI Agent Self-Edits And Learns
Steve Gickling
March 25, 2026
1:29 PM
![]() Michael Chadwick Fry Faces Abuse Charges
Sumit Kumar
March 25, 2026
1:06 PM
![]() Novaworks Launches With $8 Million Seed
Sumit Kumar
March 25, 2026
12:19 PM
Intel’s Desert Bet Deserves Cautious Confidence
Joe Rothwell
March 25, 2026
11:48 AM
![]() MIT Model Wins ECMWF Forecasting Contest
Rashan Dixon
March 25, 2026
11:45 AM
![]() When AI Experimentation Turns Into Architectural Debt
Kirstie Sands
March 25, 2026
11:33 AM
![]() MIT and HPI Launch AI Creativity Hub
Rashan Dixon
March 25, 2026
10:37 AM
![]() TSA Staff Work Without Pay Amid Standoff
Steve Gickling
March 25, 2026
10:06 AM
How To Uninstall Apps on Android: Remove, Disable & Force Delete Any App (2026)
Editorial Staff
March 25, 2026
10:04 AM
How To Screen Record on Android: Built-In Recorder, Settings & Audio Capture (2026)
Editorial Staff
March 25, 2026
10:04 AM
How To Restore Android Phone From Google Backup: Apps, Settings & Data (2026)
Editorial Staff
March 25, 2026
10:02 AM
How To Restart Android Phone: Soft Restart, Force Restart & Scheduled Restart (2026)
Editorial Staff
March 25, 2026
10:01 AM
How To Screen Mirror on Roku: Android, iPhone, Windows & Mac (2026)
Editorial Staff
March 25, 2026
9:59 AM
How To Connect Phone to TV: Screen Mirror, Cast & HDMI for Android (2026)
Editorial Staff
March 25, 2026
9:58 AM
How To Unblock a Number on Android: Find and Unblock Contacts, Calls & Texts (2026)
Editorial Staff
March 25, 2026
9:57 AM
How To Take a Screenshot on Samsung: Every Galaxy Method Explained (2026)
Editorial Staff
March 25, 2026
9:38 AM
How To Screen Record on Samsung: Galaxy S, A, Z Fold & Z Flip (2026)
Editorial Staff
March 25, 2026
9:37 AM
Why Is My Phone So Slow? Fix a Laggy Android Phone Step by Step (2026)
Editorial Staff
March 25, 2026
9:37 AM
What Is My Phone Number? How To Find Your Number on Android (2026)
Editorial Staff
March 25, 2026
9:35 AM
How To Transfer Data From Android to iPhone: Apps, Photos, Contacts & Messages (2026)
Editorial Staff
March 25, 2026
9:34 AM
Why Won’t My Phone Turn On? Fix an Android Phone That Won’t Power Up (2026)
Editorial Staff
March 25, 2026
9:33 AM
![]() Should You Self-Host or Outsource Your Observability Stack?
Sumit Kumar
March 25, 2026
9:19 AM
AI Chatbots Are Agreeing With Users Who Express Suicidal Thoughts
Editorial Staff
March 25, 2026
9:00 AM
![]() Seven Design Choices That Shape Developer Experience
Steve Gickling
March 24, 2026
4:34 PM
|










