I'm wondering if it's possible to use one foreign key to connect to multiple tables?
I want to have athletes that can be either in a running or jumping event. For this they get an event number for the event they are in (they can only participate in one event).
For instance:
CREATE TABLE running (event_num decimal primary key,
event_time varchar(20) not null,
);
CREATE TABLE jumping (event_num decimal primary key,
event_time varchar(20) not null,
);
CREATE TABLE athletes (athlete_num decimal primary key,
event_num decimal not null,
);
insert into running VALUES
(111, "43 seconds");
insert into jumping VALUES
(222, "5 seconds");
insert into athletes VALUES
(101, 111),
(102, 222);
I want to link the athletes table to the jumping and running tables via one key (event_num).
The first row in "athletes" is linked to "running" via 111 (using the event_num foreign key).
The second row in "athletes" is linked to "jumping" via 222 (also using the event_num foreign key, but this time the linked value is found in the "jumping" table)
#What I'm trying to achieve
foreign key (event_num) REFERENCES running(event_num) AND REFERENCES jumping(event_num)
The first row in "athletes" is linked to "running" via 111 (using the event_num foreign key).
The second row in "athletes" is linked to "jumping" via 222 (also using the event_num foreign key, but this time the linked value is found in the "jumping" table)