liveBook · Manning

Transitive dependency

As explained in Grokking Relational Database Design

A transitive dependency is a functional dependency in which a nonkey attribute depends on another nonkey attribute that depends on a key.

A transitive dependency occurs when a nonkey column depends on another nonkey column, which in turn depends on the table’s key. For example, employee_id determines department_id, and department_id determines department_name. The department name therefore depends on employee_id through department_id. section 6.7

Transitive dependencies create repeated data and can cause insertion, update, and deletion anomalies. A normalized table keeps columns directly dependent on its key and on nothing else. section 6.2 section 6.7

To remove a transitive dependency:

  • Identify the dependency chain: key → nonkey attribute → another nonkey attribute. section 6.7
  • Move the indirectly dependent attributes into a separate table whose primary key determines them. section 6.7
  • Keep the determining key in the original table as a foreign key. section 6.7
  • Check whether multiple relationships form an unnecessary cycle across tables. section 6.8

Employee and department data

Instead of repeating department_name in every employee row, create department(department_id, department_name) and employee(employee_id, department_id, ...). The department name is now dependent on department_id, while employee-specific columns depend directly on employee_id. section 6.7

A three-table cycle

A purchase table can contain payment_id and email while payment_method also links payment_id to user through email. Removing the direct email link from purchase can break the transitive dependency, though query speed and cost may affect the final design. section 6.8

Use the dependency diagram to trace which employee attributes depend directly on employee_id and which depend indirectly through department_id. section 6.7

How Grokking Relational Database Design covers it

How deep it goes
Defines the dependency chain, explains its anomalies, and demonstrates decomposition with foreign keys; it stops short of later normal forms.
Examples
Uses employee-department data and a purchase-payment_method-user relationship to expose direct and indirect dependencies.
What it assumes
Assumes basic familiarity with tables, keys, columns, and relationships while defining dependency rules through examples.
What you can do after
Diagnose transitive dependencies and redesign affected tables with separate entities and foreign-key links.
How it connects
Connects transitive dependency to functional dependency, primary keys, foreign keys, normalization, 3NF, BCNF, and data anomalies.

Also explained in

Compare how 2 books explain transitive dependency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.