Apparently it is totally legal to do this:
In red, you see that I have two tables whose primary key is linked to a single foreign key. Why is this allowable? Why would anyone want to do this? Does this cause a problem? If I inserted a row into the [tt][EatenFruits_LOG][/tt] table, how the hell would I know later whether the data was meant to be the id of an apple or an orange?
Code:
CREATE TABLE [Apples]
(
[id] int NOT NULL IDENTITY PRIMARY KEY,
[yumminess] int NOT NULL
)
CREATE TABLE [Oranges]
(
[id] int NOT NULL IDENTITY PRIMARY KEY,
[yumminess] int NOT NULL
)
CREATE TABLE [EatenFruits_LOG]
(
[fruit] int NOT NULL,
[when] datetime NOT NULL DEFAULT GetDate()
)
[red]ALTER TABLE [EatenFruits_LOG]
ADD FOREIGN KEY ([fruit])
REFERENCES [Apples]([id])
ALTER TABLE [EatenFruits_LOG]
ADD FOREIGN KEY ([fruit])
REFERENCES [Oranges]([id])[/red]
In red, you see that I have two tables whose primary key is linked to a single foreign key. Why is this allowable? Why would anyone want to do this? Does this cause a problem? If I inserted a row into the [tt][EatenFruits_LOG][/tt] table, how the hell would I know later whether the data was meant to be the id of an apple or an orange?