I have two tables a and b like this:
a: id, type
b: a_id, ...
There is a limitation for which the references of a in b can only be those which have type equal to a limited set of values.
Is it possible to include a CHECK for an attribute of the referenced table or do you have a better design idea?
Best Answer
It's possible to add
a_type
tob
, and have check constraint onb.a_type
. Breaking normalization a bit allows enforcing storing details in proper table . In Oracle you can have 2 constrains supported by the same index, for instance PK ona.id
, and UNIQUE on (a.id,a.type
) , then some tables that require proper type may have FK to(a.id,a.type)
, and other tables that don't care about type can refer toa.id
.