Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have Four Tables
(1) Table1 has FK (F1)
(2) Table2 has PK (F2)
(3) Table2 has PK (F3)
(4) Table2 has PK (F4)
i Want to Make Three Relations between Table1,Table2,Table3 and Table4
As described above Table1 has the FK and the 3 others have the Primary Keys
i did that but when i try to enter data to Table1 it does not see only the Relation between Table1 and Table 2
Simply i Want To Add in the FK of Table1 an ID that must be in Table2 or Table3 or Table4 Primary Key

any one can help me in doing that

thanks in advanced
Posted
Updated 19-May-12 4:27am
v3
Comments
Sergey Alexandrovich Kryukov 18-May-12 19:05pm    
No kidding? :-)
--SA
Sander Rossel 19-May-12 10:28am    
Edited. We are not blind and can read text even when it's not all bold :)

1 solution

Isn't this obvious that this is impossible and makes no sense?

Please see this explanations of the foreign key: http://en.wikipedia.org/wiki/Foreign_key[^].

In particular, pay attention for the code samples. Look: for a table named TABLE_NAME, a foreign key is always defined in association with some other table named other_table. Think a bit: why is that so? Otherwise, you would not have information on what a value of a foreign key is referring to. The keys (primary) can be only made unique in the scope of a single table. If you have a value of some foreign key, you would not be able to determine the table without the name of a foreign key which is unique in the scope of the table using this key. This information presents in the database schema. This is how it's possible to establish one-to-one, one-to-many and many-to-many relations between tables: through the multitude of one-to-one relations between primary and foreign keys.

In practical terms, in a simplest case, you need to create three foreign keys in Table1 to establish relations with three other tables.

—SA
 
Share this answer
 
v2
Comments
Yasser El Shazly 18-May-12 20:40pm    
I'd like to Make three one to many relation but Only one FK of Table One With Other Three PK of the Other three Tables , When i did that i found that
when i Enter New Row in table 1 The FK column must be ID Found in Table2 or 3 or 4 but that does not happen as he check if the Value i Entered Found in Table2 PK Or not if yes The Row added well , if no Throw Exception although this Value Found in table3 may be in table4 i think he just Take Care with The First Relation ... (Table1 - Table2) and the others not , although they already Exist
Sergey Alexandrovich Kryukov 21-May-12 14:10pm    
And..?
I think you should think at my answer and accept if formally if you get it (green button) -- thanks.
--SA
Sander Rossel 19-May-12 10:29am    
Good answer, have a 5 :)
Sergey Alexandrovich Kryukov 19-May-12 21:46pm    
Thank you, and yes, I'll look at your question right away.
--SA
Sander Rossel 19-May-12 10:31am    
On a side note, I posted a question just yesterday and I'm sure you'll have some answers, tips, opinions... I'm very interested in them. So if you find some time please take a look at my question. It's very much appreciated. Thanks :)
http://www.codeproject.com/Questions/387125/A-question-on-IInterface-design

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900