Definition
A relation schema is in third normal form(3NF) with respect to a set of functional dependencies if:
For all functional dependencies , where , at least one of the following holds:
- is trivial. (i.e., )
- is a superkey of . (i.e., )
- Each attribute in is contained in a candidate key for .
- Note that each attribute may be in a different candidate key.
If a relation is in BCNF, then it is in 3NF also. The third condition is a minimal relaxation to BCNF to ensure dependency preservation.
Note that for any relation schema, there always exists a lossless, dependency preserving decomposition into 3NF.
Example
Consider a schema with the functional dependencies and .
Then, the candidate keys are and .
Although is not in BCNF, is in 3NF.
Testing for 3NF
Unlike testing for BCNF, testing for 2NF need not check all functional dependencies in ; it only requires to check only functional dependencies in itself.
Let be a relation schema, and let be the set of functional dependencies.
- For every functional dependency , compute .
- If , does not violate 3NF.
- Otherwise if is not a superkey of , verify if each attribute in is contained in a candidate key of .
This test is rather more expensive, since it involves finding candidate keys. This test is shown to be NP-hard.
Decomposition into 3NF
The above algorithm ensures that:
- Each relation schema is in 3NF.
- Decomposition is dependency preserving and lossless.