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] 
  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




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



Create A Table




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




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



Output


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



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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250