Third normal form (3NF) is a level of database normalization defined by English computer scientist Edgar F. Codd. A relation (or table, in SQL) is in third normal form if it is in second normal form and also lacks non-key dependencies, meaning that no non-prime attribute is functionally dependent on (that is, contains a fact about) any other non-prime attribute. In other words, each non-prime attribute must depend solely and non-transitively on each candidate key. William Kent summarised 3NF with the dictum that "a non-key field must provide a fact about the key, the whole key, and nothing but the key". An example of a violation of 3NF would be a Patient relation with the attributes PatientID, DoctorID and DoctorName, in which DoctorName would depend first and foremost on DoctorID and only transitively on the key, PatientID (via DoctorID's dependency on PatientID). Such a design would cause a doctor's name to be redundantly duplicated across each of their patients. A database compliant with 3NF would store doctors' names in a separate Doctor relation which Patient could reference via a foreign key. 3NF was defined, along with 2NF (which forbids dependencies on proper subsets of composite keys), in Codd's paper "Further Normalization of the Data Base Relational Model" in 1971, which came after 1NF's definition in "A Relational Model of Data for Large Shared Data Banks" in 1970. 3NF was itself followed by the definition of Boyce–Codd normal form in 1974, which seeks to prevent anomalies possible in relations with several overlapping composite keys.
Definition of third normal form Codd's definition states that a relation R is in 3NF if and only if it is in second normal form (2NF) and every non-prime attribute of R is non-transitively dependent on each candidate key. A non-prime attribute of R is an attribute that does not belong to any candidate key of R. Codd defines a transitive dependency of an attribute set Z on an attribute set X as a functional dependency chain X → Y → Z that must be satisfied for some attribute set Y, where it is not the case that Y → X, and all three sets must be disjoint. A 3NF definition that is equivalent to Codd's, but expressed differently, was given by Carlo Zaniolo in 1982. This definition states that a table is in 3NF if and only if for each of its functional dependencies X → Y, at least one of the following conditions holds:
X contains Y (that is, Y is a subset of X, meaning X → Y is a trivial functional dependency), X is a superkey, every element of Y \ X, the set difference between Y and X, is a prime attribute (i.e., each attribute in Y \ X is contained in some candidate key). To rephrase Zaniolo's definition more simply, the relation is in 3NF if and only if for every non-trivial functional dependency X → Y, X is a superkey or Y \ X consists of prime attributes. Zaniolo's definition gives a clear sense of the difference between 3NF and the more stringent Boyce–Codd normal form (BCNF). BCNF simply eliminates the third alternative ("Every element of Y \ X, the set difference between Y and X, is a prime attribute."). The definition offered by Zaniolo can be shown to be equivalent to the Codd definition in the following way (the trivial case is by default same statements): let X → A be a nontrivial functional dependency (i.e., one where X does not contain A) and let A be a non-prime attribute. Also let Y be a candidate key of R. Then Y → X. Further since A is a non-prime attribute, therefore A cannot determine X (A → X not possible) because in that case some AM would form the candidate key (where M = Y \ A (or simply Y, since A is non-prime and thus not an element of Y)). Therefore, A is not transitively dependent on Y (X is not prime attribute as per 2NF but both Y and X can be non-primes if we do not follow the Codd's definition for 3NF. If we follow Codd's definition Y is candidate key and we are showing that following that definition is equivalent to following Zaniolo's definition) if and only if there is a functional dependency X → Y (simply reversing one of the dependency to avoid transitivity), i.e., if and only if X is a candidate key of R in case R consists only these two dependencies otherwise X is a prime attribute, but the second case violates 2NF. So, for a dependency Y → X, X and Y are candidate keys or at least Y is a candidate key, then the relation is in 3NF as per Codd (this is the 2. condition of Zaniolo's definition). The only other way to follow the definition of Codd for 3NF is not to consider any non-prime being dependent, that is to make every such A only a prime attribute i.e. there shouldn't be a non-prime attribute that depends on another non-prime attribute (2NF allows dependency on candidate key or non-prime attribute) that may lead to transitivity (in short avoid non-prime to non-prime dependency). By allowing such dependencies where right hand side is only primes we follow Codd's third normal form as well as third condition of Zaniolo's definition. It is to be noted that either or each of A, X and Y can be single attributes or a combination thereof but are necessarily disjoint. One can write X → Y equivalently as X → XY and one may thus observe the Zaniolo equivalence for Codd by performing the set difference between the dependent and the determinant. In short, Zaniolo points to a loophole more clearly than the transitive definition. 3NF gives a massive "escape clause" (loophole) to the RHS. One interesting point here is before 3NF we were bothered about LHS and even in BCNF we are bothered about that. For a dependency (X → Y) to pass 3NF, even if X is not a Super Key / Candidate Key the following conditions must be true:
Y is a Prime Attribute (RHS loophole)
Example
Design which violates 3NF The following relation, with the composite key {Name, Year}, fails to meet the requirements of 3NF. The non-prime attributes WinnerName and WinnerBirthdate are only transitively dependent on the composite key via their dependence on the non-prime attribute WinnerID. This creates redundancy and the potential for inconsistency in the case that a winner of multiple tournaments is accidentally given different dates of birth in different tuples.
Design which complies with 3NF To bring the relation into compliance with 3NF, WinnerID, WinnerName and WinnerBirthdate can be transferred to a separate table.
… excerpt ends here. Continue reading the full article.