I have 3 tables:
Race - id PKRacer - id PK - rankWinner - id PK - race_id FK(Race.id) - racer_id FK(Racer.id) - rank - prize UNIQUE CONSTRAINT (race_id, rank)
Racer.rank
is a non-unique values, as some players can tie to a rank. I try to have records in Winner
to have its rank
match the Racer.rank
that it references to. The unique constraint is to ensure that each race has only one 1st place.
The integrity between Winner.rank
and Racer.rank
is to enforcing if we later update Racer.rank
, we will have to update the value in Winner
as well, or remove that Winner
row. How can I enforce that matching?
Other separate question:- Is there a keyword that describe what I try to accomplish? I try to search with "referential integrity", "foreign constraint non-unique"... but none gets me to satified result.