Maximum Cardinality

Maximum Cardinality

In Figure 5-5, the maximum cardinality is shown inside the diamond that represents the relationship. The three parts of this figure show the three basic maximum cardinalities in the E-R model.

Figure 5-5(a) shows a one-to-one (abbreviated 1:1) relationship. In a 1:1 relationship, an entity instance of one type is related to at most one entity instance of the other type. The Employee_Identity relationship in Figure 5-5(a) associates one EMPLOYEE instance with one BADGE instance. According to this diagram, no employee has more than one badge, and no badge is assigned to more than one employee.

The Computer_Assignment relationship in Figure 5-5(b) illustrates a one-to-many (abbreviated 1:N) relationship. Here, a single instance of EMPLOYEE can be associated with many instances of COMPUTER, but a COMPUTER instance is associated with just one instance of EMPLOYEE. According to this diagram, an employee can be associated with several computers, but a computer is assigned to just one employee.

The positions of the 1 and the N are significant. The 1 is close to the line connecting EMPLOYEE, which means that the 1 refers to the EMPLOYEE side of the relationship. The N is close to the line connecting COMPUTER, which means that the N refers to the COMPUTER side of the relationship. If the 1 and the N were reversed and the relationship were written N:1, an EMPLOYEE would have one COMPUTER, and a COMPUTER would be assigned to many EMPLOYEEs.

When discussing one-to-many relationships, the terms parent and child are sometimes used. The parent is the entity on the 1 side of the relationship, and the child is the entity on the many side of the relationship. Thus, in a 1:N relationship between DEPARTMENT and EMPLOYEE, DEPARTMENT is the parent and EMPLOYEE is the child (one DEPARTMENT has many EMPLOYEEs).

Figure 5-5(c) shows a many-to-many (abbreviated N:M) relationship. According to the Qualification relationship, an EMPLOYEE instance can be associated with many SKILL instances, and a SKILL instance can be associated with many EMPLOYEE instances. This relationship documents that fact that an employee may have many skills, and a skill may be held by many employees.

Sometimes students wonder why we do not write many-to-many relationships as N:N or M:M. The reason is that cardinality in one direction may be different than the cardinality in the other direction. In other words, in an N:M relationship, N need not equal M. An EMPLOYEE

Figure 5-5

(a) One-to-One Relationship

BADGE Cardinality

Three Types of Maximum

EMPLOYEE

Employee_Identity

(b) One-to-Many Relationship

Computer_Assignment

(c) Many-to-Many Relationship

EMPLOYEE

N:M

SKILL

Qualification

Chapter 5 Data Modeling with the Entity-Relationship Model

can have five skills, for example, but one of those skills can have three employees. Writing the relationship as N:M highlights the possibility that the cardinalities may be different.

Sometimes the maximum cardinality is an exact number. For example, for a sports team, the number of players on the roster is limited to some fixed number, say, 15. In that case, the maximum cardinality between TEAM and PLAYER would be set to 15 rather than to the more general N.

Relationships like those in Figure 5-5 are sometimes called HAS-A relationships . This term is used because each entity instance has a

relationship to a second entity instance. An employee has a badge, and a badge has an employee. If the maximum cardinality is greater than one, then each entity has a set of other entities. An employee has a set of skills, for example, and a skill has a set of employees who have that skill.