Reputation: 9
I need to define a constraint where tuples in a booking table can only have a value in musician (foreign key attribute from musician table) or actor (foreign key attribute from actor table), and must have one of these, but not both. At first I came up with this solution -
1. select any tuple from booking, call it x;
2. project x's musician column, call it y;
3. project x's actor column, call it z;
4. count(y) + count(z) = 1;
This works but also unintentionally imposes the constraint that the 'empty' booking's musician and actor columns cannot contain an empty string. How can I fix this issue?
P.S. I'm aware that count() isn't always part of relational algebra but I am permitted to use it for this purpose.
Upvotes: 0
Views: 253
Reputation: 33808
The obstacles you are facing are these:
The solutions are:
Booking
for exclusively {Actor|Musician}
, you need to model {Actor|Musician}
... which is a Person
Person
can be {Actor|Musician|Both}
, ie. non-exclusiveBooking
for {Actor|Musician}
needs to be exclusive.Easily modelled in the Relational paradigm. As a consequence, the SELECT
is simple and straight-forward.
The Data Model in IDEF1X/ER Level (not ERD) is:
The Standard for Relational Data Modelling since 1983 is IDEF1X. For those unfamiliar with the Standard, refer to the short IDEF1X Introduction.
For full definition and usage considerations re Subtypes, refer to Subtype Definition.
Upvotes: 2