Databases / DBMS

2NF

1NF plus no partial dependence of a non-key attribute on part of a composite key.

Level: intermediate

What is it?

Second Normal Form (2NF) requires a relation to be in 1NF and every non-prime attribute to depend on the whole of each candidate key, not merely a proper subset. Partial dependencies matter primarily when candidate keys are composite.

Why does it matter?

Partial dependencies repeat facts unnecessarily. Decomposing them reduces update anomalies and ensures each non-key fact is tied to the complete identity it describes.

Mental model

If the key is (student_id, course_id), ask whether an attribute needs both values to be determined. A student's name depends only on student_id, so it belongs with the student, not the enrollment pair.

How it works

  • 2NF is evaluated against candidate keys and functional dependencies, not just whether the table has a primary key.
  • A table with only single-attribute candidate keys has no partial dependency on a proper subset of such a key.
  • Non-prime attributes are attributes that are not part of any candidate key.
  • Decomposition should preserve information through a lossless join; dependency preservation should also be considered.
  • 2NF does not remove every transitive dependency; 3NF addresses another class of dependency.

Steps

  • Identify all candidate keys and functional dependencies.
  • Find any non-prime attribute determined by only a proper subset of a composite key.
  • Move those dependent attributes into a relation keyed by that subset.
  • Keep a relation for the original full-key fact and join relations back by their key.

Real-world usage

  • Normalizing enrollment, order-line, and other composite-key tables.
  • Solving normalization questions by listing dependencies.

Common mistakes

  • Checking 2NF using only the chosen primary key while ignoring other candidate keys.
  • Thinking a repeated value automatically proves a 2NF violation without examining functional dependencies.
  • Assuming 2NF automatically implies 3NF.

Interview questions

What is a partial dependency?

A non-prime attribute depends on a proper subset of a candidate key, rather than on the entire candidate key.

When is a relation automatically in 2NF with respect to partial dependency?

When every candidate key is a single attribute, there is no proper nonempty subset of that key on which a partial dependency could exist.

Prerequisites

Related concepts

Continue learning

Browse the full computer science library