vk101 said
Quote:
Thanks for your reply. I'm new to this so I can't picture how a bidirectional foreign key relationship enforces a mandatory 1:1 relationship.
Can't you still make it a 1:m relationship by simply adding, say, 5 more rows in one of the two tables that point to the primary key of a row in the other table?
|
Let's see what happens when we do as vk101 suggests.
There is a table T1 with columns (p1 [primary Key], a1, a2, p2 [Foreign Key from table T2])
There is a second table T2 with columns (p2 [primary key], b1, b2, p1 [foreign key to Table T1])
Now let's try and create the bi-directional data as suggested.
Table T1 (p1, a1,a2, p2)
---------
Row 1: 101, 'S1', 'S2', 201
Table T2 (p2, b1, b2, p1)
---------
Row 1: (201, 'T1', 'T2', 101)
You say you want to create five rows in T2 that refer to T1's row with primary key 101. Let's create four more rows in T2.
Table T2:
----------
Row 2: (202, 'U1', 'U2', 101)
Row 3: (203, 'V1', 'V2', 101)
Row 4: (204, 'W1', 'W2', 101)
Row 5: (205, 'X1', 'X2', 101)
So far, no problem.
But remember, a bi-directional relation must
exist in both tables!
Let's see what we have to do for table T1's data. We must add
four more rows each with primary key 101 and foreign keys 202, 203, 204 and 205 respectively. This clearly is not possible since it violates the primary key constraint of table T1! Clearly, you can see that there can be only one row with primary key 101 in T1; and hence a bi-directional relationship may have only one value at each end.
Hence, Tony's statement that a bi-directional relationship mandates a 1:1 relationship.
Hope that helps.
Ravi