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 ...

Get Inside Microsoft® SQL Server™ 2005, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.