Definitionintro
Second normal form (2NF)
Also called 2NF.
A relation in first normal form in which no non-prime attribute depends on a proper subset of a candidate key.
Second normal form is the first of Codd's normal forms that uses functional dependencies. It forbids a non-prime attribute that depends on only a part of a candidate key. The normalization page compares all the normal forms, and the third normal form page treats the stronger condition that is used in practice. This page gives the exact definition of 2NF, a test for it, and the examples that separate it from 1NF and 3NF.
Definition
Let be a finite set of attributes and a finite set of FDs over . Keys, prime attributes and closures are taken with respect to , as on the candidate key page.
- An attribute is fully dependent on a set if and for each proper subset . If but is not fully dependent on , the dependence is partial.
- Definition (Codd 1972). A schema in first normal form is in second normal form if each non-prime attribute is fully dependent on each candidate key. Equivalently, there is no candidate key , proper subset and non-prime attribute with .
A test. The schema is in 2NF if and only if, for each candidate key and each , the closure contains no non-prime attribute. Proof. If and with non-prime, pick . Then , so . The other direction is the case . The test needs all keys, so it can take time exponential in when there are many keys, and finding the prime attributes is NP-hard in general (see the prime attribute problem).
3NF implies 2NF. Use Zaniolo's form of 3NF: for each FD implied by with , either is a superkey or is prime. Suppose is not in 2NF, with a key , a set and a non-prime with . Then , because and is in no key. is not a superkey, because it is a proper subset of the key . So violates 3NF.
Edge cases. If every key has one attribute, the only proper subset of a key is , so the schema is in 2NF unless for a non-prime . If every attribute is prime, the schema is in 2NF, since there is no non-prime attribute to test.
Examples and non-examples
- Not in 2NF: a partial dependency. with student, course, grade and student name, and . The only key is , and is non-prime. makes depend on part of the key, so the schema is in 1NF and not in 2NF. A student's name is stored once for each course the student takes. Splitting on into and is lossless by Heath's theorem, and both parts are in 2NF.
- In 2NF, not in 3NF. with employee, department and department name, and . The only key is , a single attribute, so the schema is in 2NF. is a transitive dependency on the key, so it is not in 3NF.
- Not in 2NF, although the primary key has one attribute. with course, teacher, section and department, and : each section has one course and one teacher, each course and teacher pair has one section, and each course belongs to one department. The keys are and , since while and . So is the only non-prime attribute. makes depend on the part of the key , so the schema is not in 2NF. A check that looks only at the primary key finds nothing to test and misses this.
- All attributes prime. with has the keys and . Every attribute is prime, so it is in 2NF, and in fact in 3NF, but not in BCNF.
- No FDs. If , the only key is and every attribute is prime, so the schema is in 2NF, and also in BCNF.
Related definitions
- First normal form. 2NF assumes 1NF, atomic values in each column. Each 2NF schema is in 1NF by definition, and shows that the converse is false.
- Third normal form. 3NF also forbids a non-prime attribute that depends on a key through a non-key set, as in . It implies 2NF, as shown above, and has a lossless, dependency-preserving synthesis algorithm, which makes 2NF of mostly historical interest.
- BCNF. BCNF drops the exception for prime attributes. It implies 3NF and so 2NF.
- Partial dependency. The FD with a proper subset of a key and non-prime is the pattern that 2NF forbids. Splitting it off into is always lossless, by Heath's theorem, and keeps the FD.
References
- E. F. Codd, Further normalization of the data base relational model, in R. Rustin (ed.), Data Base Systems, Courant Computer Science Symposia 6, Prentice-Hall (1972), 33 to 64, full functional dependence on a key and the definitions of second and third normal form
- Jeffrey D. Ullman, Principles of Database and Knowledge-Base Systems, Volume I, Computer Science Press (1988), Section 7.6 (normal forms for relation schemes, 2NF, 3NF and BCNF)
- Serge Abiteboul, Richard Hull and Victor Vianu, Foundations of Databases, Addison-Wesley (1995), Chapter 11 (design and dependencies), normal forms based on functional dependencies
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 8MCYKZ Edit this page History Report an error Markdown