Concepts / Third Normal Form: Removing Transitive Dependencies

Third Normal Form: Removing Transitive Dependencies

Redundancy occurs when the same information is stored multiple times across different rows in a table, such as repeating an artist's name in every track row.

  • Programming

The Attractive Shortcut

Suppose a Track table already stores a song title and play count. You now want to add artist information. The most natural approach is to add artist details directly to the Track table and fill them in for every row. With a few tracks, this design looks clean and reasonable. The hidden problem appears when the same artist information is repeated across many rows.

containsreferencesTrack rowtitle, play_count,artist_idartist_idartist referenceArtistartist name and details
How does a track row determine an artist name indirectly through artist_id, and why does that create a transitive dependency?

Tracing the Repeated Values

Redundancy occurs when the same information is stored multiple times across different rows. For example, if an artist has many tracks, the artist name and other artist details may appear once in every track row. The track rows are different, but the artist information is the same. The more tracks an artist has, the more copies of that information the table contains.

Track titlePlay countArtist nameEye color
Track A1200Frank SinatraBlue
Track B950Frank SinatraBlue
Track C700Frank SinatraBlue

Illustrative rows showing the same artist details repeated for multiple tracks.

repeatsrepeatsrepeatsTrack AFrank Sinatra; BlueArtist detailsFrank Sinatra; BlueTrack BFrank Sinatra; BlueTrack CFrank Sinatra; Blue
Which values are duplicated when the same artist name is stored in every track row, and how do the rows relate to one another?

Why Transitive Dependencies Matter

The track and the artist are related, but they are not the same kind of information. A track row identifies a track and can use an artist reference to identify its artist. Artist attributes, such as an artist name or eye color, describe the artist. If those attributes are copied into every track row, the track table stores artist information indirectly and repeatedly rather than storing it in one dedicated place. This indirect dependency is the design problem addressed by Third Normal Form.

Redundancy is the storage of the same information multiple times across different rows. In a normalized design, each piece of information should be stored in exactly one place, while references such as foreign keys connect related data in separate tables.

The Update Anomaly

Changing an Artist Attribute

Frank Sinatra has 1200 songs in the redundant table. The eye-color value should change from Blue to Light Blue. What must be updated?

Locate the copies: The artist details appear in every one of the 1200 track rows.

Apply the change: The update must touch all 1200 rows if every copy is to remain consistent.

Consider a partial update: If the system crashes or application logic updates only some rows, the table can contain both Blue and Light Blue for the same artist.

Evaluate the result: The database is now inconsistent, and the rows do not reveal which version is correct.

One fact required many updates, creating an update anomaly when the copies do not all change together.

partial updatemissed updateTrack AOld nameTrack ANew nameTrack BOld nameTrack BOld name
What happens when an artist changes their name but only some of the repeated artist-name values are updated?

This risk grows with the size of the database. A repeated attribute across millions or billions of rows creates a large maintenance task. Normalization prevents the problem by keeping the attribute in one place, so changing it does not require changing every related track row.

The Deletion Anomaly

Redundancy also couples two different facts: the existence of a track and the existence of an artist. Suppose an artist has only one track in the table. If that track is deleted because it is no longer available, the row containing the artist details disappears too. Deleting a track has accidentally deleted the only stored record of the artist.

delete trackonly copy removedLast trackartist details includedTrack tabletrack removedArtist detailsonly copyArtist detailslost
What information is accidentally lost when deleting the last track associated with an artist whose details are stored only in the track table?

Separating the Tables

The normalized solution is to create a separate Artist table. Store each artist's information once in that table. The Track table keeps track-specific information and uses a foreign key to reference the related artist. The relationship remains available, but the artist name and other artist attributes are no longer copied into every track row.

identifiesreferencesArtist tableartist details stored onceartist_idforeign-key targetTrack tabletrack details and artist_id
How does moving artist attributes into a separate Artist table remove repeated values while preserving the relationship to tracks?
Redundant designSeparated design
Artist details are repeated in track rowsArtist details are stored once in Artist
An artist update may require many row updatesThe artist information has one stored copy to maintain
Deleting the last track can delete artist informationTrack information and artist information are stored separately
The relationship is represented by repeated valuesThe relationship is represented through a foreign-key reference

Recognizing the Pattern

  • Assuming a small test table proves the design is safe

    Redundancy becomes more difficult to maintain as the number of related rows grows.

    Fix: Ask whether the same fact is being stored repeatedly and whether it belongs in a separate table.

  • Updating only one repeated copy of an artist attribute

    The table becomes inconsistent, and it is no longer clear which value is correct.

    Fix: Store the artist attribute once and reference the artist from Track rows.

  • Treating a track deletion as unrelated to artist data without checking the design

    The artist information was stored only as part of the track row.

    Fix: Separate artist information from track information.

  • Confusing a relationship with a repeated copy of descriptive data

    A foreign-key reference can connect the tables without copying the artist details into every track row.

    Fix: Keep the relationship through a reference and store each fact in one appropriate place.

MEDIUM

A course table stores a student's name in every enrollment row. A student takes five courses. If the student's name changes, what maintenance problem can occur? If the enrollment in the student's only course is deleted, what information might be lost?

Hints
  • Look for the value that is repeated across enrollment rows.
  • Separate the question about changing a value from the question about deleting a row.
  • Use the Artist and Track pattern as a comparison.

A Reliable Design Test

  1. Find values that repeat across multiple rows.
  2. Ask which real-world object each repeated value describes.
  3. Check whether changing that value would require updating many rows.
  4. Check whether deleting one row could remove the only copy of another fact.
  5. Move the repeated object's attributes into a separate table.
  6. Use a foreign-key reference to preserve the relationship between the tables.

What do you think happens?

An instructor teaches 20 courses, and the instructor's name and email are stored in every course row. If the email changes, what is the likely result in this design?

  • Only one value needs to change
  • Twenty repeated values may need to change
  • The course rows cannot be affected
  • Deleting a course automatically fixes the email
Reveal answer

Answer: Twenty repeated values may need to change

The source example identifies repeated instructor information across 20 course rows. A change to the instructor's email therefore creates the same maintenance risk as repeated artist information.

Key Takeaways

  1. Redundancy means storing the same information repeatedly across rows.
  2. Repeated artist attributes create update anomalies when only some copies change.
  3. Deleting the last related row can cause a deletion anomaly by removing the only copy of another fact.
  4. Third Normal Form addresses this pattern by separating artist data from track data.
  5. Foreign-key references preserve relationships without repeating the related entity's descriptive data.

Key Takeaways

  • Redundancy occurs when one fact, such as an artist's name or eye color, is copied into many track rows.
  • An update anomaly occurs when repeated copies are not all changed consistently.
  • A deletion anomaly occurs when deleting a track also removes the only stored copy of an artist's details.
  • Third Normal Form reduces these problems by storing artist attributes once in an Artist table and connecting tracks with a foreign key.