Thursday, August 30, 2012

SQL SERVER - What is user defined data type, and how to create


 It is very esay dont worry about how to use and create it below example just run only. 

It allows defining its own T- SQL User Defined Data Type and you can use this UDDT to entire Database.
See the following example-

-- TO CREATE USER DEFINED DATA TYPE WITH VARCHAR DATA TYPE

EXEC SP_ADDTYPE TYPE1, 'VARCHAR(50)','NULL'

-- TO CREATE USER DEFINED DATA TYPE WITH INT DATA TYPE 
--Example 2 (run this Full Script)

EXEC SP_ADDTYPE  @TYPENAME =TYPE2,

@PHYSTYPE= INT,

@NULLTYPE=NULL,

@OWNER= DBO

-- Declare the variable and data type is 'TYPE2'
DECLARE @MYVARIALBE TYPE2

-- Set the value in vairaible
SET @MYVARIALBE = 100

-- Get the value from varaible
SELECT @MYVARIALBE AS MYVALUE

-- Drop user defined data type
Drop  type  TYPE2


Like and Share to SQL Integrity Blog

No comments:

Post a Comment

Thank You !!!!