2007 Aug 24 9:20 AM
Hello,
can anyone tell me how I assign more than 1 foreign key to a table for the same field?
Is that even possible?
I created a diagram of what I want to achieve, I hope this is clear, if not, just ask.
<a href="http://www.quodlibet.be/files/foreign_key.jpg">figure</a>
2007 Aug 24 9:24 AM
well you gotta work the other way round. your tables child_a and child_b nood to implement that field and have it marked as foreign key.
2007 Aug 24 9:26 AM
I tried that, but then I got an error message when I tried to insert a new record to my 'main' table, saying it didn't exist in the other table.
But I'll check it again just to make sure.
Thnx.
2007 Aug 24 9:33 AM
yeah that is the relational data model.
you can not create a record which has a reference to something that doesnt exist.
e.G. in an sales order, we have a field for customer. well you cant create a sales order and fill in a customer that doesnt exist.
thats exactly the thing for which foreigh keys are made.
2007 Aug 24 9:35 AM
You get me wrong, what I am saying is that it should be possible to create a customer if a sales order does not exist, but like I said, i'll just double check if I didn't make any mistakes.
Thanks anyway.
2007 Aug 24 10:07 AM
I don't seem to get it right,
I have three tables, like in the figure in my initial post.
In table CHILD_A I create a foreign key (with check required) linked to the field ID in the table MAIN.
When I add a new record to the table MAIN, I get the error message that I defined in the foreign key.
What I expected was this error to occur when I added a field to table CHILD_A that didn't have a corresponding record in table MAIN.
2007 Aug 24 10:09 AM
hmmm ok, thnen i lost overview, maybe you goto the Tables MARA, MARC, MARD, MARM and check how they have solved the issue there.
2007 Aug 24 10:43 AM
After triple-checking my program, I found that the problem only occured when I had a search help linked to that field on my screen.
So it does work like I suspected, and like you guys said it would, but the check was more severe than I thought.
Thank you all.
2007 Aug 24 9:32 AM
Hi
yes you can creat
for example
MARA, MARC,MARD
these 3 tables having MATNR field as the same
MARD and MARC are the two tables which having FK relation to MARA
try this
reward if usefull