My question is related to this one: How to keep foreign key relations consistent in a "diamond-shaped" system of relationships
I have a very similar problem: A venue contains many seats. A venue also hosts many events. I need to keep track of which seats are booked in each event. This information is kept in the event_seat table, which has identifying relationships with both event and seat (i.e. its primary key identifies both an event and a seat).
I want to enforce the restriction that each row in event_seat must refer to an event and to a seat that belong to the same venue. I considered converting event -> venue into an identifying relationship by making venue_id
part of the primary key for event
, like so:
Doing so would allow me to define two foreign keys for event_seat
as follows:
(venue_id, event_id) references event(venue_id, event_id)
(venue_id, seat_id) references seat(venue_id, seat_id)
This definition would guarantee the desired restriction (the event must take place in the same venue to which the seat belongs). However, venue_id
is actually a function of event_id
, so (venue_id, event_id)
is not a minimal superkey. Doesn't this violate some fundamental principle about primary keys? What other options do I have?