【Database】Relationship between Tables

Posted by 西维蜀黍 on 2018-11-12, Last Modified on 2024-05-02

Relationship

One-to-one relationship

In a one-to-one relationship, one record in a table is associated with one and only one record in another table. For example, in a school database, each student has only one student ID, and each student ID is assigned to only one person.

One-to-many relationship

In a one-to-many relationship, one record in a table can be associated with one or more records in another table. For example, each customer can have many sales orders.

Many-to-many relationship

A many-to-many relationship occurs when multiple records in a table are associated with multiple records in another table. For example, a many-to-many relationship exists between customers and products: customers can purchase various products, and products can be purchased by many customers.

Participation

Total participation (Compulsory, Mandatory)

for humans, “hasBiologicalFather” is a many-to-one relationship from Person to Man with total participation.

Consider two entities EMPLOYEE and DEPARTMENT related with the help of relationship WORKS_FOR.

If a company policy states that every employee must work for a department, then an employee entity can exist only if it participates in at least one WORKS_FOR relationship instance. Thus, the participation of EMPLOYEE in WORKS_FOR is called total participation, meaning that every entity in the total set of employee entities must be related to a department entity via WORKS_FOR.

Partial participation (Opitional)

Consider two entities EMPLOYEE and DEPARTMENT related with the help of relationship MANAGES.

Here, not all employees are expected to manage a department, so the participation of EMPLOYEE in the MANAGES relationship type is partial.

Reference