Concepts / One-to-Many Relationships

One-to-Many Relationships

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.

  • 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.

Artisttable boxRelationshipconnecting lineNotationcardinality and optionalityTracktable boxconnectsconnectsuses
What do the table boxes, relationship line, and notation symbols each contribute to a database relationship?
Key point

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.

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

Artist and Track

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

  1. 1
    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.

  2. 2
    Identify the entity containing the multiple related records

    Several track records can be associated with one artist, so Track is the many side.

  3. 3
    State the relationship

    The relationship is one Artist to many Tracks.

Result

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.

dashexactly one; requiredcirclezero or onecrow's footmany; requiredcrow's footzero or manyoptionality changesoptionality changes
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.

artist_idPKArtistone sideTrackmany sideartist_idFKcontainsreferenced bycontains
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?
Worked example

Connecting Artist to Track

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

  1. 1
    Place the primary key

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

  2. 2
    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.

  3. 3
    Connect the key columns

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

Result

The Track foreign key references the Artist primary key.

Key point

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. 1
    Draw one rectangular box for each table and place the table name at the top.
  2. 2
    List the columns inside each table box.
  3. 3
    Mark the primary key in the table on the one side.
  4. 4
    Mark the foreign key in the table on the many side.
  5. 5
    Draw a line connecting the related key columns.
  6. 6
    Place a single dash at the one end and a crow's foot at the many end.
  7. 7
    Add a perpendicular dash or circle at each end to show whether participation is mandatory or optional.
  8. 8
    Read both ends together to verify the intended cardinality and optionality.
Artistartist_id PKonedashTrackartist_id FKmanycrow's foothasrelationship linehas
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

  • Common mistake

    Looking at only one end of the relationship line

    What it looks like

    Reading the crow's foot without checking the symbol attached to the other table

    Why it fails

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

    Do this instead

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

  • Common mistake

    Treating the circle as the many symbol

    What it looks like

    Assuming a circle means multiple records

    Why it fails

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

    Do this instead

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

  • Common mistake

    Putting the foreign key on the one side

    What it looks like

    Adding the relationship column to Artist instead of Track in the Artist and Track example

    Why it fails

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

    Do this instead

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

  • Common mistake

    Ignoring optionality after identifying cardinality

    What it looks like

    Reporting only that a relationship is one-to-many without checking for circles or perpendicular dashes

    Why it fails

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

    Do this instead

    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

Separate the questions of cardinality, optionality, and key placement.

Key Takeaways

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

At a glance

  • 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.

Related concepts

More concepts starting with O