RE: foreign keys depending on two different tables in mysql

  • From: "Rodney Haynie" <RHaynie@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 18 Sep 2007 20:09:17 -0400

Don't think I totally understand where you are going with that one Sina.

I would say the best way to implement this would be to have a different
field for each foreign key.  That way the foreign key would be setup like
normal, and the program code would be designed to know which one to use and
when.
 
So table C would have a field for tableA_id and tableB_id.
The primary keys of table A and B would either be setup to allow nulls, or
you would need a record with an id of zero.

HTH.
Rodney



-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Sina Bahram
Sent: Tuesday, September 18, 2007 7:24 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: foreign keys depending on two different tables in mysql

Couldn't he combine  the restraints into a view that checked against a
different table?

Take care,
Sina

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Rodney Haynie
Sent: Tuesday, September 18, 2007 4:56 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: foreign keys depending on two different tables in mysql

I searched, I saw, I am reporting:
Sorry to say that I still do not think this is possible.
The assignment of a foreign key is directly linked to only one table.
Even if it was possible to assign multiple foreign keys for the same field,
it would not be possible to determine which table to check the restraint
against.

HTH.
-Rodney


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Rodney Haynie
Sent: Tuesday, September 18, 2007 4:31 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: foreign keys deppending on two different tables in mysql

I really do not think you can do this by setting up as foreign keys.
I would do the same as you had already mentioned... Implement by code.

But I am interested and will take a peak up in the docs to see if this is
possible.

If I find anything that will make this possible, I shall report back.

I'll look now.


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Marlon Brandão
de Sousa
Sent: Tuesday, September 18, 2007 3:31 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: foreign keys deppending on two different tables in mysql

Hello,
I have this situation:
Table a has an id and a name field
Table b has an id and a name field
Table c has an id field, an external code field and a name field The
external code field of table c must be an existing id in table a or in table
b, thus it is a foreign key.
I do know, for example, how to make the external code field from table c
deppend on the id field of table b ... what I don't know is if it is
possible to make it refer to the id field from table b or to the id field of
table a.
I know this would cause some ambiguity in a ondelete rule, but what I need
is to guarantee that the external field from table c will accept only values
present on table a or on table b.
Do you know if this is possible and, if it is, how to do it in the mysql
database?
Sure I can implement this in the code but I was woundering if it is possible
to build this kind of rule in the database.
Thanks
Marlon
--
When you say "I wrote a program that crashed Windows," people just stare at
you blankly and say "Hey, I got those with the system, for free."
Linus Torvalds
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: