On Oct 27, 2006, at 10:38 AM, Paul McNett wrote:

Using the invoice & customer tables example,
the invoice table has an iClientId column that points
at the clients PK, iid.  So iClientId is a foreign
key.  I would think invoice would be the parent and
client would be the child -- do you agree or disagree?

Disagree. There's one customer to many invoices, not one invoice to many customers.

Parent/child is an unfortunate choice of terms. Typically in designing database systems, the better terminology is independent/ dependent.

The choice of which is which depends on the particular process. If you are looking at a list of customers, the set of selected invoices is dependent on the chosen customer. That is why the invoice is considered a child of customer.

However, imagine a module in that app in the shipping department. They get an invoice, and need to see the related information. In that case, the customer record that is displayed is dependent on the selected invoice. Select a different invoice; get a different customer.

The choice of how to link related tables depends on the nature of the relationship. For 1:M relations, it makes sense for the 'many' table to have a link to the single record it is related to. For M:M tables, neither has a foreign key to the other; those are maintained in separate tables typically called 'allocation' or 'relation' tables. For 1:1 relations, it really doesn't matter, but typically if one table is considered 'primary' and the other 'supplemental', the supplemental table contains a FK linking back to the main.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to