Partager via


Temporary Relationships Between Tables

You can use work areas and table aliases to create temporary relationships between tables. Temporary relationships cause the record pointer in one table, known as the child table, to follow the movements of the record pointer in another table, known as the parent table. For example, suppose you want establish a relationship between a customer table and an orders table so that when you move the record pointer in the customer table to a particular customer, the record pointer in the orders table moves to the record with the same customer number.

You can create different relationships between tables. For example, in a one-to-many relationship, you can select a record in the parent table or "one" side of the relationship and access multiple related records in the child table or "many" side of the relationship. For more information about relationships you can create, see Identifying Relationships.

Typically, you set a temporary relationship between tables that have a common field using a relational expression. The relational expression is typically the index expression of the controlling index in the child table. Therefore, when you create a relationship between the parent table and the index of the child table, selecting a record in the parent table selects only those records in the child table whose index key matches the index key for the parent record you select.

After you open tables and create relationships, you can view the aliases and relationships for those tables in the Data Session window.

Open table aliases and temporary relationships in the Data Session window

FoxPro Data Session Order

Relationships in Single Tables

You can also create a relationship between records in a single table, or a self-referential relation. This type of relationship can be useful when you have all the information you need in a single table. For example, suppose you have an employee table. By creating a self-referential relationship in the table, you can select employee records for those employees who report to each manager as you navigate to each manager record in the table.

Relationships Between Tables in a Data Environment

If you are using a form to work with tables, you can use the data environment of the form to create and store these relationships with the form. Relationships you create in the data environment open automatically when you run the form. For information on creating a data environment, see Creating Forms.

See Also

Tasks

How to: Set Temporary Relationships Between Tables

Reference

Work Areas in Data Sessions

Other Resources

Managing Tables in Data Sessions

Working with Tables (Visual FoxPro)