Algorithm Search⌘K

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 UU be a finite set of attributes and FF a finite set of FDs over UU. Keys, prime attributes and closures X+X^+ are taken with respect to FF, as on the candidate key page.

  • An attribute AA is fully dependent on a set XX if F⊨X→AF \models X \to A and F⊭X′→AF \not\models X' \to A for each proper subset X′⊊XX' \subsetneq X. If F⊨X→AF \models X \to A but AA is not fully dependent on XX, the dependence is partial.
  • Definition (Codd 1972). A schema (U,F)(U, F) 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 KK, proper subset X⊊KX \subsetneq K and non-prime attribute AA with F⊨X→AF \models X \to A.

A test. The schema is in 2NF if and only if, for each candidate key KK and each B∈KB \in K, the closure (K−{B})+(K - \{B\})^+ contains no non-prime attribute. Proof. If X⊊KX \subsetneq K and F⊨X→AF \models X \to A with AA non-prime, pick B∈K−XB \in K - X. Then X⊆K−{B}X \subseteq K - \{B\}, so A∈X+⊆(K−{B})+A \in X^+ \subseteq (K - \{B\})^+. The other direction is the case X=K−{B}X = K - \{B\}. □\square The test needs all keys, so it can take time exponential in ∣U∣|U| 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 X→AX \to A implied by FF with A∉XA \notin X, either XX is a superkey or AA is prime. Suppose (U,F)(U, F) is not in 2NF, with a key KK, a set X⊊KX \subsetneq K and a non-prime AA with F⊨X→AF \models X \to A. Then A∉XA \notin X, because X⊆KX \subseteq K and AA is in no key. XX is not a superkey, because it is a proper subset of the key KK. So X→AX \to A violates 3NF. □\square

Edge cases. If every key has one attribute, the only proper subset of a key is ∅\emptyset, so the schema is in 2NF unless F⊨∅→AF \models \emptyset \to A for a non-prime AA. 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. Grade(S,C,G,N)\mathrm{Grade}(S, C, G, N) with student, course, grade and student name, and F={SC→G, S→N}F = \{SC \to G,\ S \to N\}. The only key is SCSC, and NN is non-prime. S→NS \to N makes NN 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 S→NS \to N into SNSN and SCGSCG is lossless by Heath's theorem, and both parts are in 2NF.
  • In 2NF, not in 3NF. Emp(E,D,N)\mathrm{Emp}(E, D, N) with employee, department and department name, and F={E→D, D→N}F = \{E \to D,\ D \to N\}. The only key is EE, a single attribute, so the schema is in 2NF. D→ND \to N is a transitive dependency on the key, so it is not in 3NF.
  • Not in 2NF, although the primary key has one attribute. Section(C,T,S,D)\mathrm{Section}(C, T, S, D) with course, teacher, section and department, and F={S→CT, CT→S, C→D}F = \{S \to CT,\ CT \to S,\ C \to D\}: 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 SS and CTCT, since S+=CT+=CTSDS^+ = CT^+ = CTSD while C+=CDC^+ = CD and T+=TT^+ = T. So DD is the only non-prime attribute. C→DC \to D makes DD depend on the part CC of the key CTCT, so the schema is not in 2NF. A check that looks only at the primary key SS finds nothing to test and misses this.
  • All attributes prime. Addr(C,S,Z)\mathrm{Addr}(C, S, Z) with F={CS→Z, Z→C}F = \{CS \to Z,\ Z \to C\} has the keys CSCS and SZSZ. Every attribute is prime, so it is in 2NF, and in fact in 3NF, but not in BCNF.
  • No FDs. If F=∅F = \emptyset, the only key is UU and every attribute is prime, so the schema is in 2NF, and also in BCNF.
  • First normal form. 2NF assumes 1NF, atomic values in each column. Each 2NF schema is in 1NF by definition, and Grade\mathrm{Grade} 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 Emp\mathrm{Emp}. 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 X→AX \to A with XX a proper subset of a key and AA non-prime is the pattern that 2NF forbids. Splitting it off into XAXA is always lossless, by Heath's theorem, and keeps the FD.

References

  1. 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
  2. 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)
  3. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/8MCYKZ/text.yaml