Second Normal Form (2NF)
2NF ensures every non-prime attribute depends on the entire candidate key, not just part of it. It only matters when a relation has a composite key. The footgun is assuming single-attribute keys automatically satisfy 2NF.
Why it exists
Database normalization was developed to structure relations so that dependencies between attributes are handled cleanly. When a relation has a composite candidate key made of multiple attributes, a non-prime attribute might be determined by only part of that key. This creates a partial dependency, which 2NF was designed to eliminate. Edgar F. Codd defined 2NF as the level above 1NF where every non-prime attribute must depend on the entire candidate key, not merely a subset of it.
The mental model
Treat a composite candidate key like a complete identifier. If a non-prime attribute can be understood by looking at only one piece of that identifier, then it is not truly describing the whole identifier. It belongs to a separate relation where that piece alone is sufficient to identify it.
How it works
A relation is in 2NF if it is already in 1NF and contains no partial dependencies. A partial dependency exists when a non-prime attribute is functionally dependent on only a proper subset of the attributes making up a candidate key. To satisfy 2NF, every non-prime attribute must depend on the whole set of attributes of every candidate key. If an attribute depends on just part of a candidate key, the relation must be decomposed so that attribute moves to a relation where the subset it depends on becomes the entire key.
When to use it
Use 2NF when designing or reviewing any relation that is in 1NF and has a composite candidate key. If the key consists of multiple attributes, examine each non-prime attribute to verify that it requires all of those attributes to be determined. This check matters whenever a relation uses a multi-attribute identifier.
When not to use it
A relation whose candidate keys are all single attributes is automatically in 2NF as long as it is in 1NF, because a single attribute has no proper subset that can functionally determine another attribute. Therefore, the 2NF check is unnecessary when no composite candidate keys exist.
One canonical example
Consider a relation with a candidate key composed of attribute A and attribute B. Suppose a non-prime attribute C is functionally dependent only on attribute A. Because C depends on a proper subset of the candidate key, the relation is not in 2NF. The correction is to form a new relation with attribute A as the key and attribute C as the non-prime attribute, while the original relation retains A and B along with any attributes that depend on the full combination.
Interview question
Which of the following describes a 2NF violation in a relation that is in 1NF and has a composite candidate key?
- a.A non-prime attribute is functionally dependent on only one attribute of the composite candidate key.Correct
- b.A non-prime attribute depends on another non-prime attribute that is not part of any candidate key.
- c.A non-prime attribute is functionally dependent on the entire composite candidate key.
- d.A prime attribute is functionally dependent on a subset of the composite candidate key.
Why? this is the answer
2NF eliminates partial dependencies, meaning every non-prime attribute must depend on the whole composite candidate key, not just a subset. Option B describes a transitive dependency, which violates 3NF, not 2NF.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
- #databases
- #normalization
- #2nf
- #relational-model
- #schema-design
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on databases — each one lists the topics its interview covers.
See open roles