The Entity-Relationship Model

Read this chapter and pay attention to the main concepts, kinds of entities, types of attributes, and types of keys. Take notes on the three relationship types and complete the exercise at the end of the chapter.

Types of Relationships

Below are descriptions of the various types of relationships.


One to many (1:M) relationship

A one to many (1:M) relationship should be the norm in any relational database design and is found in all relational database environments. For example, one department has many employees. Figure 8.7 shows the relationship of one of these employees to the department.

Figure 8.7. Example of a one to many relationship.


One to one (1:1) relationship

A one to one (1:1) relationship is the relationship of one entity to only one other entity, and vice versa. It should be rare in any relational database design. In fact, it could indicate that two entities actually belong in the same table.

An example from the COMPANY database is one employee is associated with one spouse, and one spouse is associated with one employee.


Many to many (M:N) relationships

For a many to many relationship, consider the following points:

  • It cannot be implemented as such in the relational model.
  • It can be changed into two 1:M relationships.
  • It can be implemented by breaking up to produce a set of 1:M relationships.
  • It involves the implementation of a composite entity.
  • Creates two or more 1:M relationships.
  • The composite entity table must contain at least the primary keys of the original tables.
  • The linking table contains multiple occurrences of the foreign key values.
  • Additional attributes may be assigned as needed.
  • It can avoid problems inherent in an M:N relationship by creating a composite entity or bridge entity. For example, an employee can work on many projects OR a project can have many employees working on it, depending on the business rules. Or, a student can have many classes and a class can hold many students.

Figure 8.8 shows another another aspect of the M:N relationship where an employee has different start dates for different projects. Therefore, we need a JOIN table that contains the EID, Code and StartDate.

Figure 8.8. Example where employee has different start dates for different projects.


Example of mapping an M:N binary relationship type

  • For each M:N binary relationship, identify two relations.
  • A and B represent two entity types participating in R.
  • Create a new relation S to represent R.
  • S needs to contain the PKs of A and B. These together can be the PK in the S table OR these together with another simple attribute in the new table R can be the PK.
  • The combination of the primary keys (A and B) will make the primary key of S.


Unary relationship (recursive)

A unary relationship, also called recursive, is one in which a relationship exists between occurrences of the same entity set. In this relationship, the primary and foreign keys are the same, but they represent two entities with different roles. See Figure 8.9 for an example.

For some entities in a unary relationship, a separate column can be created that refers to the primary key of the same entity set.

Figure 8.9. Example of a unary relationship.


Ternary Relationships

A ternary relationship is a relationship type that involves many to many relationships between three tables.

Refer to Figure 8.10 for an example of mapping a ternary relationship type. Note n-ary means multiple tables in a relationship. (Remember, N = many.)

  • For each n-ary (> 2) relationship, create a new relation to represent the relationship.
  • The primary key of the new relation is a combination of the primary keys of the participating entities that hold the N (many) side.
  • In most cases of an n-ary relationship, all the participating entities hold a many side.

Figure 8.10. Example of a ternary relationship.