← Back to SQL, page 10

sql-0200 · Medium mid

What is a transitive dependency, and how does third normal form remove it?

A transitive dependency is when a non-key column depends on another non-key column rather than on the key directly, for example employees(id, dept_id, dept_name), where dept_name depends on dept_id. 3NF requires 2NF plus no transitive dependencies, so dept_name moves to a departments table.

Full answer

In employees(id, name, dept_id, dept_name), the chain is id → dept_id → dept_name. Every Engineering employee repeats 'Engineering'; renaming the department means updating all of them, and a department with no employees cannot be stored.

The fix keeps dept_id in employees and moves the name:

text
employees(id, name, dept_id)
departments(id, name)

This is the STAFF sample schema used throughout this bank. A short way to remember 3NF: every non-key column depends on "the key, the whole key, and nothing but the key". 1NF gives a key, 2NF covers "the whole key", and 3NF covers "nothing but the key".

Key points

  • Transitive: key → non-key → another non-key
  • 3NF = 2NF plus no transitive dependencies
  • Move the dependent columns to a table keyed by the middle column
  • 'The key, the whole key, and nothing but the key'

Common mistakes

  • Calling every repeated value a 3NF violation
  • Removing a needed foreign key along with the dependent column

Follow-ups

  • How does BCNF differ from 3NF?
  • Is storing a city and a postal code together a 3NF problem?

Tips

  • Use the employees and departments example