snippetMinor
create User Defined Type with CHECK
Viewed 0 times
createwithusertypecheckdefined
Problem
In PostgreSQL one can create a User Defined Type with an implicit CHECK by doing the following:
In Sybase ASE 15.7 I've figured that the following is almost equivalent (except for the CHECK):
How do I make a CHECK part of the user-defined type definition in Sybase?
CREATE DOMAIN OrdinalT AS INTEGER CHECK (value >= 0);In Sybase ASE 15.7 I've figured that the following is almost equivalent (except for the CHECK):
sp_addtype OrdinalT, "INTEGER";How do I make a CHECK part of the user-defined type definition in Sybase?
Solution
You cannot make a check condition a part of the type definition syntactically, but you can create a rule:
and bind it to the data type:
In order to modify the rule later, you will have to drop and recreate it. Before being dropped, the rule must be unbound:
Note that the argument in the last statement is not the rule itself but the type to which the rule is bound.
CREATE RULE OrdinalTRule AS @value >= 0and bind it to the data type:
sp_bindrule OrdinalTRule, OrdinalTIn order to modify the rule later, you will have to drop and recreate it. Before being dropped, the rule must be unbound:
sp_unbindrule OrdinalTNote that the argument in the last statement is not the rule itself but the type to which the rule is bound.
Code Snippets
CREATE RULE OrdinalTRule AS @value >= 0sp_bindrule OrdinalTRule, OrdinalTsp_unbindrule OrdinalTContext
StackExchange Database Administrators Q#161765, answer score: 2
Revisions (0)
No revisions yet.