O'Reilly logo

Inside Microsoft® SQL Server™ 2005, Fourth Edition by Kalen Delaney

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

User-Defined Data Types

A user-defined data type (UDT) provides a convenient way for you to guarantee consistent use of underlying native data types for columns known to have the same domain of possible values. For example, perhaps your database will store various phone numbers in many tables. Although no single, definitive way exists to store phone numbers, in this database consistency is important. You can create a phone_number UDT and use it consistently for any column in any table that keeps track of phone numbers to ensure that they all use the same data type. Here’s how to create this UDT:

CREATE TYPE phone_number FROM varchar(20) NOT NULL;

And here’s how to use the new UDT when you create a table:

CREATE TABLE customer ( cust_id smallint NOT ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required