How to read a data model

This modeling tidbit excerpted from Data Modeling Made Simple

Cardinality represents the symbols on both ends of a relationship that define the number of instances of each entity that can participate in the relationship. It is through cardinality that the data rules are captured and enforced. Without cardinality, the most we can say about a relationship is that two entities are connected in some way through a rule. For example, person and company have some kind of relationship, but we don’t know much more than this.

 

The domain of values to choose from to represent cardinality on a relationship is limited to three values: zero, one, or many. Many (some people read it as more) means any number greater than one. We can’t specify an exact number (other than through documentation), as in “A car has four tires.” We can only say, “A car has many tires.”

 

Each side of a relationship can have a combination of zero, one, or many. Through the specification of one or many, the structural portion of the cardinality represents the quantity of each entity instance in the relationship. The RI portion of the cardinality focuses on ensuring valid values through the specification of zero or one.

 

Each of the cardinality symbols are illustrated through the following example of product and order line. A product is something that an organization sells in the hope of making a profit. An order line exists for each product on a particular order. For example, an order for five widgets and two doodads would mean two order lines in one order, with each order line tying back to a particular product. Formalizing the rules between product and order line, we have

 

Each product can appear on one or many order lines.

Each order line must contain one and only one product.

 

Fig. 5.1 captures these business rules.

 

Fig. 5.1 Product and order line, take 1

You need to know only three symbols to read any relationship. The small vertical line means “one.” The circle means “zero.” The triangle with a line through the middle means “many.” Some people call the “many” symbol a crow’s foot. The label (“Appear on”) on the line in this example helps in reading the relationship and understanding the rule that the relationship represents.

 

Every relationship has a parent and child. The parent entity appears on the “one” side of the relationship, and the child appears on the “many” side of the relationship. When you read a relationship, it is a good practice to start on the “one” side, because the entity there is typically the more independent of the two entities and sometimes provides a context for the child entity. Starting with the parent also adds consistency when interpreting the rules.

 

We use the word each in reading each relationship, starting with the parent side.

 

The relationship in fig. 5.1 is therefore read as follows:

 

Each product can appear on zero, one, or many order lines.

Each order line must belong to one and only one product.

 

This relationship most closely matches the original business rule that we talked about several paragraphs earlier. Let’s change the cardinality slightly between these two entities and read the resulting business rules.

 

Fig. 5.2 Product and order line, take 2

 

Fig. 5.2 is interpreted as follows:

 

Each product can appear on one or many order lines.

Each order line can belong to zero or one product.

 

Fig. 5.3 Product and order line, take 3

Fig. 5.3 is interpreted as follows:

 

Each product can appear on zero or one order line.

Each order line can belong to one and only one product.


 

Fig. 5.4 Product and order line, take 4

Fig. 5.4 is interpreted as follows:

Each product can appear on one or many order lines.

Each order line can belong to one or many products.