Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parent-child file with 2 fields (keys) to link
Message
From
06/11/2010 16:15:41
 
 
To
06/11/2010 05:51:53
Maybelle Tan
Oversea Feeds Corp.
Manila, Philippines
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 8
OS:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01488435
Message ID:
01488478
Views:
60
>If a have a parent file with 2 fields as key (example: Customer Code and Invoice No.), how do I link them to my child file containing the same 2 fields among other fields? Also, how can I use a grid in a form for the child file with this?

Common practice is to structure your tables a little differently. Each table should have a primary key, which is usually an autoincrementing integer or GUID column. Your table structures could look like this:
* Parent table (Customers)
Cust_PKey  (Primary Key)
Cust_Code
CustName
....

* Child Table (Invoices)
Inv_PKey  (Primary Key)
Cust_PKey  ("foreign key")
Inv_Number
...

* In many cases, with Invoices you will want multiple Invoice Line Items per Invoice,
* so you'd want a child table of Invoices:
* Grandchild table (InvoiceLineItems):
InvLI_PKey  (Primary Key)
Inv_PKey  (Foreign Key)
Product_ID
Quantity
....
Using primary and foreign keys like this lets you link Customers, Invoices (and potentially Invoice Line Items) in the manner you want.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform