Articles → SQL SERVER → User Defined Data Types In SQL Server

User Defined Data Types In SQL Server

Scenario Of Using The User Defined Data Types

  1. Create a rule
  2. Create the user-defined data type
  3. Create a table

Create A Rule

create rule [dbo].[City_rule] 
  @value NOT LIKE '%[^a-z]%' 
and len(@value) > 0

Create The User Defined Data Type

CREATE TYPE [dbo].[citytype] FROM [varchar](20) NOT NULL

Picture showing the Properties option in the context menu of the user defined type
Click to Enlarge

Picture showing a window to apply rule on the user defined data type in sql server
Click to Enlarge

Create A Table

Picture showing adding a column in the table of user defined data type
Click to Enlarge

Insert into myTab values('Delhi')
Insert into myTab values('Delhi6')


Picture showing the error message when user tries to enter the numeric value in the column
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Thursday, June 10, 2021


Your Email Id  
Query/FeedbackCharacters remaining 250