To move the primary key from each parent table into the matching external keys of the named child database tables.
Attach {child-table} [… {child-table}]
Where {child-table} is the name or filelist number of one or more child tables.
Each relationship indicates a many-to-one connection between parent and child tables. Many-to-one relationships have the following properties:
The parent table has a primary key, a key that uniquely identifies each record. It is composed of one or more fields.
The primary key of the parent table is also stored in the child table. It is called an external key.
Attach moves the primary key from each parent table into the matching external keys of the named child tables.
Use the Table Editor in the Studio to define relationships between parent and child tables.
In the following example, a table of locations serviced is used to access a large vendor table. The location table is read and if there is a record, the external keys (city and state) are moved into a vendor table.
Open Vendor
Open Location
Move "Fl" to Location.State
Move "Miami" to Location.City
Find EQ location by 1 // assume index 1 segments are state, city
// If there is a record in the location, find a vendor for this city
If (Found) Begin
// Move related fields into parent table transaction buffer
Attach Vendor
// Now we can find by state & city in the child table vendor
Find EQ Vendor by 1 // assume index 1 segments are state, city
End
If the command includes multiple parent tables, attaches are done to such tables in the order in which they are named.
Attaches will be done only to those child tables which are open, using whatever data is in the parent table at the time of attach. If a parent table is open, but no record is in its buffer, attach will be performed on the clear buffer of the parent table, thereby clearing the external keys of the child tables.
Attach moves data from parent tables to child tables. The relate command moves data from child tables to parent tables.
The save command automatically executes an attach, eliminating the requirement to use the attach command in most situations.
You can also pass table numbers to the attach command.