Technical data

5.9.2.3 One-to-Many Relationships Between Records of the Same Type
To build a one-to-many relationship between records of the same type, the DBA
uses junction records. In a one-to-many relationship between records of the same
type, either record type can be the junction record. However, in Figure 5–24 the
WK_GROUP record type serves as the junction record because the EMPLOYEE
record type has most of the relationship’s data.
The record type EMPLOYEE includes all employees—supervisors, managers,
and so forth. A manager can have many supervisors and a supervisor can have
many employees. Conversely, an employee can have only one supervisor, and a
supervisor can have only one manager.
Figure 5–24 One-to-Many Relationship Between Records of the Same Type
ZK−1501−GE
WK_GROUP
EMPLOYEE
BACHMAN DIAGRAM
EMPLOYEE
EMPLOYEE
WK_GROUP
DATABASE REPRESENTATION
CONSISTS_OF
MANAGES
CONSISTS_OF
MANAGES
To show a relationship between employees (that is, who works for whom),
Figure 5–24 uses the record type WK_GROUP as a link to establish an owner-
to-member relationship. For example, a manager or supervisor would own a
WK_GROUP record occurrence in the MANAGES set, and the same WK_GROUP
occurrence owns any number of EMPLOYEE records in the CONSISTS_OF set.
The relationship would be as follows: one occurrence of EMPLOYEE owns a
WK_GROUP record occurrence, which in turn owns zero or more occurrences of
the EMPLOYEE record type.
A one-to-many relationship between records of the same type is different from a
many-to-many relationship between records of the same type because:
An employee can have only one manager, while a part can be used on many
subassemblies.
The EMPLOYEE record type can participate both as an owner and a member
in its relationship with WK_GROUP.
The PART record type can participate only as an owner in its relationship
with COMPONENT.
Example 8–6 shows how to use DML for hierarchical relationships. The example
uses the diagram in Figure 5–24.
5–22 Database Programming with HP COBOL