Tuesday, March 8, 2011

SQL SERVER: User Defined Data Types

To create user defined data types, use either of the 2 methods.

1. Using T-SQL syntax

CREATE TYPE [Schema].[Datatype Name] FROM Datatype [NULL / NOT NULL]

E.g.
USE [AdventureWorks2008]
GO

/****** Object: UserDefinedDataType [dbo].[Test] ******/
CREATE TYPE  [dbo].[Test]  FROM  [int]  NOT NULL
GO

2. Using SSMS also we can acheive this.

In database expand the Programmability section, the Type section and the User Defined Data Type section
Right click and select New User-defined Data Type and a pop up appears as below
Fill appropriate data for Schema, Name and Data type fields and save it.


Reference : DP (http://dptechnicalblog.blogspot.com/ )

No comments:

Post a Comment