Multiple foreign key reference in a single field

[expired user #4788]'s profile image [expired user #4788] posted 14 years ago in General Permalink
Hi Dudes,

I need to have a foreign key field that should refer from two tables. for an example,

table_a
--------
1 a_id primary key,
2 name

table_b
--------
1 b_id primary key,
2 name

table_c
-------
1 c_id
2 name
3 key_id (i.e, it should be foreign key from either table_a or table_b. it may have value of either table_a's id or table_b's id

Can any one of u help me to get this script to create table.

Thanks
Saga
ansgar's profile image ansgar posted 14 years ago Permalink
I don't think that's possible with an InnoDB hardcoded foreign key. There is no way to enter "table_a.a_id OR table_b.b_id" in a CREATE TABLE statement. Of course, you can do logic on your own, without InnoDB and real foreign keys.

Please login to leave a reply, or register at first.