--How to create User Define DataType with Default and Rules
--Creating DefaultCREATE
AS 'UnknownNumber' -- this is default value when no value is specifiedGO
--Creating RuleCreate
AS
(@phone='UnknownNumber') or (len(@phone) = 14 and substring(@phone,1,1) = '+' and substring(@phone,5,1) = '-')--Rule says when there is no value it place 'UnknownNumber'
--or lenght should be of 14 number and number should begin with '+' and '-' after 3rd digit to identify the state code
--Creting User Define DataTypeEXEC SP_ADDTYPE --Sp to create datatypePhoneNumber, -- Name of new user defined data type that is being created'varchar(25)', -- Base system data type of SQL Server'not null', -- To specify that null values are allowed for this data type or not'dbo' -- Owner of this being created user defined data type Rule Rule_Phn DEFAULT Default_Phn
--Creating DefaultCREATE
AS 'UnknownNumber' -- this is default value when no value is specifiedGO
--Creating RuleCreate
AS
(@phone='UnknownNumber') or (len(@phone) = 14 and substring(@phone,1,1) = '+' and substring(@phone,5,1) = '-')--Rule says when there is no value it place 'UnknownNumber'
--or lenght should be of 14 number and number should begin with '+' and '-' after 3rd digit to identify the state code
--Creting User Define DataTypeEXEC SP_ADDTYPE --Sp to create datatypePhoneNumber, -- Name of new user defined data type that is being created'varchar(25)', -- Base system data type of SQL Server'not null', -- To specify that null values are allowed for this data type or not'dbo' -- Owner of this being created user defined data type Rule Rule_Phn DEFAULT Default_Phn
No comments:
Post a Comment