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















Create a rule




create rule [dbo].[City_rule] 
  as 
  @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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250