Concepts / One-to-Many Relationships

One-to-Many Relationships

Crow's Foot Diagrams use boxes to represent tables and lines with notation symbols to represent relationships between tables.

  • Programming

Seeing the Database

A database with two tables and one relationship can be easy to understand. Real-world databases may contain dozens or hundreds of tables with many connections. Trying to keep all those relationships in your head becomes difficult. A graphical data model turns that abstract structure into something you can see and reason about at a glance.

A Crow's Foot Diagram is a visual language for database structure. Each table appears as a box containing its table name and columns. Lines connect related tables, and symbols at the ends of those lines describe how many records can participate and whether participation is required or optional.

connectsconnectsusesArtisttable boxRelationshipconnecting lineNotationcardinality and optionalityTracktable box
What do the table boxes, relationship line, and notation symbols each contribute to a database relationship?

The diagram is not decoration. It makes entities, keys, relationships, and relationship constraints visible so a database design can be communicated and examined more easily.

Tracing One to Many

A one-to-many relationship connects one instance of one entity to multiple instances of another entity. The source material uses an Artist table and a Track table to illustrate this structure: one artist can be connected to multiple tracks.

connected toconnected toconnected toArtistoneTrackrecord 1Trackrecord 2Trackrecord 3
How does one record in one table connect to multiple records in another table?

Artist and Track

Identify the one side and the many side in the relationship between Artist and Track.

Identify the entity that can be referenced repeatedly: An artist can be associated with multiple tracks, so Artist is the one side in this example.

Identify the entity containing the multiple related records: Several track records can be associated with one artist, so Track is the many side.

State the relationship: The relationship is one Artist to many Tracks.

Artist is the one side, and Track is the many side.

Reading Crow's Foot Symbols

Crow's Foot notation combines cardinality and optionality. Cardinality describes how many records may participate. A single dash represents one, while a crow's foot represents many. Optionality describes whether participation is required. A perpendicular dash represents mandatory participation, while a circle represents optional participation.

optionality changesoptionality changesdashexactly one; requiredcirclezero or onecrow's footmany; requiredcrow's footzero or many
How do a dash, circle, and crow's foot combine to show the allowed number of related records?
Symbol combinationMeaning
Single dash with perpendicular lineExactly one record is required
Single dash with circleZero or one record is allowed
Crow's foot with perpendicular lineMany records are required
Crow's foot with circleZero or many records are allowed

The four combinations described by Crow's Foot cardinality and optionality notation.

The vertical line, or simple dash in a relationship symbol, identifies the one end. The crow's foot has three spreading lines and identifies the many end. The circle does not mean many; it indicates that the relationship is optional and can include zero records.

Placing the Keys

A Crow's Foot table box contains the table name and its columns. The primary key is typically marked with PK or an asterisk. A foreign key is often marked with FK or a dagger symbol. In a one-to-many relationship, the primary key belongs on the one side, and the foreign key belongs on the many side.

containsreferenced bycontainsartist_idPKArtistone sideTrackmany sideartist_idFK
Where does the primary key go, where does the foreign key go, and how does the many-side table connect back to the one-side table?

Connecting Artist to Track

Place the keys for a one-to-many relationship in which one Artist can be associated with multiple Tracks.

Place the primary key: Put the Artist primary key on the one side. It uniquely identifies each Artist instance.

Place the foreign key: Put the foreign key in Track, the many-side table. It stores the primary key value that establishes the link back to Artist.

Connect the key columns: The relationship line connects the Artist primary key to the Track foreign key.

The Track foreign key references the Artist primary key.

The foreign key is not placed on the one side simply because that table is conceptually important. It is placed on the many side because multiple records there need to store the value that points back to one record on the other side.

Drawing the Relationship

  1. Draw one rectangular box for each table and place the table name at the top.
  2. List the columns inside each table box.
  3. Mark the primary key in the table on the one side.
  4. Mark the foreign key in the table on the many side.
  5. Draw a line connecting the related key columns.
  6. Place a single dash at the one end and a crow's foot at the many end.
  7. Add a perpendicular dash or circle at each end to show whether participation is mandatory or optional.
  8. Read both ends together to verify the intended cardinality and optionality.
hasrelationship linehasArtistartist_id PKonedashTrackartist_id FKmanycrow's foot
What should be added when turning two related tables, their keys, and their cardinality into a complete Crow's Foot Diagram?
EASY

A Customer table is on the one side of a relationship, and an Order table is on the many side. Describe where the primary key, foreign key, single dash, and crow's foot should appear.

Hints
  • The primary key is placed on the one side.
  • The foreign key is placed on the many side.
  • The single dash marks one, and the crow's foot marks many.

What do you think happens?

In the Artist and Track relationship, which table should contain the foreign key?

  • Artist
  • Track
  • Either table
Reveal answer

Answer: Track

Track is the many-side table, and the foreign key is placed on the many side to reference the primary key on Artist, the one side.

Avoiding Misreads

  • Looking at only one end of the relationship line

    The relationship's meaning depends on the symbols at both ends, interpreted from the perspective of their attached tables.

    Fix: Inspect both endpoints before deciding whether the relationship is one-to-one, one-to-many, or another type.

  • Treating the circle as the many symbol

    A circle indicates optionality, meaning zero is allowed. It does not indicate many.

    Fix: Use the crow's foot to identify many and the circle to identify optional participation.

  • Putting the foreign key on the one side

    The foreign key belongs on the many side and references the primary key on the one side.

    Fix: Identify the many-side table first, then place the foreign key there.

  • Ignoring optionality after identifying cardinality

    Cardinality says one or many, but optionality says whether zero is allowed or participation is required.

    Fix: Read the cardinality symbol and optionality symbol at each endpoint.

QuestionSymbol or location to inspectInterpretation
How many records?Single dash or crow's footOne or many
Is participation optional?Circle or perpendicular dashZero is allowed or participation is required
Where is the primary key?One-side tableIt uniquely identifies the one-side entity instance
Where is the foreign key?Many-side tableIt references the primary key on the one side

Key Takeaways

  1. Crow's Foot Diagrams show tables as boxes and relationships as lines with notation symbols.
  2. A one-to-many relationship connects one instance of one entity to multiple instances of another entity.
  3. A single dash represents one, while a crow's foot represents many.
  4. A perpendicular dash indicates mandatory participation, while a circle indicates optional participation.
  5. In a one-to-many relationship, the primary key is on the one side and the foreign key is on the many side.

Key Takeaways

  • Use Crow's Foot Diagrams to make complex database structures visible and easier to reason about.
  • Read both ends of a relationship line: cardinality identifies one or many, and optionality identifies whether zero is allowed.
  • A one-to-many relationship has a single dash at the one end and a crow's foot at the many end.
  • Place the primary key in the one-side table and the foreign key in the many-side table.
  • The foreign key connects each many-side record back to the appropriate one-side record.