Is foreign key reference from two different primary key from two different tables valid?
Posted
by
arundex
on Stack Overflow
See other posts from Stack Overflow
or by arundex
Published on 2012-10-07T09:35:12Z
Indexed on
2012/10/07
9:36 UTC
Read the original article
Hit count: 201
I have a foreign key that has to refer primary keys of two different tables.
Table 1: animal
animal_ id (primary key)
Table 2: bird
bird_ id (primary key)
Table 3: Pet_info
pet_id,
type ENUM ('bird', 'animal')
foreign key (pet_ id) references animal(animal_id), bird(bird_id)
So, I need to check for pet_id either from animal or bird table depending on the need. Is this valid? Or should I go for some restructuring . . .
NOTE: I referred this . . but I'm not sure whether I have to change my existing design
© Stack Overflow or respective owner