Create a User-Defined Data Type Alias
This topic describes how to create a new user-defined data type alias in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL.
In This Topic
-
Before you begin:
-
To create a user-defined data type alias, using:
Limitations and Restrictions
-
The name of a user-defined data type alias must comply with the rules for identifiers.
Security
To create a user-defined data type
-
In Object Explorer, expand Databases, expand a database, expand Programmability, expand Types, right-click User-Defined Data Types, and then click New User-Defined Data Type.
-
In the New User-defined Data Type dialog box, in the Schema box, type the schema to own this data type alias, or use the browse button to select the schema.
-
In the Name box, type a name for the new data type alias.
-
In the Data type box, select the data type that the new data type alias will be based on.
-
Complete the Length, Precision, and Scale boxes if appropriate for that data type.
-
Check Allow NULLs if the new data type alias can permit NULL values.
-
In the Binding area, complete the Default or Rule boxes if you want to bind a default or rule to the new data type alias. Defaults and rules cannot be created in SQL Server Management Studio. Use Transact-SQL. Example code for creating defaults and rules are available in Template Explorer.
To create a user-defined data type alias
-
Connect to the Database Engine.
-
From the Standard bar, click New Query.
-
Copy and paste the following example into the query window and click Execute. This example creates a data type alias based on the system-supplied varchar data type. The ssn data type alias is used for columns holding 11-digit social security numbers (999-99-9999). The column cannot be NULL.
CREATE TYPE ssn FROM varchar(11) NOT NULL ;