0

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?

2 Answers 2

2

It's possible to add a_type to b, and have check constraint on b.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 on a.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 to a.id .

0

You can use a before trigger on INSERT or UPDATE of ID to the b table. This would verify that the new value of b.id is of the correct type. This technique can also be used where the values in referenced tables can be logically disabled, but needs to be retained.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.