-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Mapping a foreign key for more than one primary key
PostPosted: Wed Sep 14, 2005 5:14 am 
Newbie

Joined: Thu Mar 24, 2005 12:08 pm
Posts: 7
Hello, I have 4 tables t1,t2,t3 each having 1 column as id and t4 having colum1 and column2 as composite primary key, column1 is a foreign key on t3's primary key, column2 should be a foreign for either t1's primary key or t2's primary key.
The actual situation is that column2 is a foreign key for t1's and t2's primary key but this is always running me into an error of foreignkey constraint.
How can I fix the problem? I know that if I create a new table for each association the problem is solved, but then I should create nearly 20 tables only for this example.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 5:31 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
I'm not a database design expert, but what you describe sounds pretty crazy - a foreign key that's a primary of one of two tables...

My feeling is that you'll have problems without end if you pursue on this track...

Maybe you could provide more background info, so that we could think of simpler alternative designs...

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 7:54 am 
Newbie

Joined: Thu Mar 24, 2005 12:08 pm
Posts: 7
Well, this is a more explained description of the problem.
I have a table customer(customer_id), a table supplier(supplier_id)
a table data(data_id).
Tha data table contains records witch will be used as selection fields within a criteria.
for example :

id| data | criterion
---------------------------
1 | country | France
---------------------------
2 | country | Germany
....

a customer can be found in more than one country, also a supplier
for that i created s table witch would contain these associations

consider for example that I have a customer Peugeot with id 10 and a supplier delphi with id 20, peugoet is located in france and germany also dephi, if i want to store these informations i would do

association table:
id1 | id2
---------------
10 | 1
10 | 2
20 | 1
20 | 2

If I would like to insert a new customer some new records should also be created in the association table. But witch primary key should then be considered customer_id or supplier_id because id1 is a foreign key on both primary keys.
I hope this was clear.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.