Functional Dependencies and Database Normalization¶
Boyce-Codd Normal Form¶
A relational schema R is in Boyce-Codd normal form if and only if for every one of its dependencies $X \to Y$, at least one of the following conditions hold:
- $X \to Y$ is a trivial functional dependency ($Y \subseteq X$)
- $X$ is a super key for schema $R$.
Example
Consider a table $R(A,B,C,D,E,F)$, with the following functional dependencies,
If we calculate the closure of $AB$,
So ${ A,B }^+ = AB^+ = ABCDE$. Then is $AB$ a superkey? No, because it didn’t include $F$, therefore it is a violation.
We can create the tables then,
and infer the functional dependencies,
We can then compute the closure on each subset of $X$ (but not $X = \varnothing$). If $X^+$ is all attributes the no need to do closure on a subset of $X$.
If we find $X$ such that $X^+$ is not all the attrib then we get a violating functional dependency.
Example
Consider the table $\text{Movies} ( \text{title}, \text{year}, \text{studioname}, \text{president}, \text{presAddr} )$ with the following functional dependencies,
where each movie is only produced by one studio. This gives us the closures,
So $\text{title}, \text{year}$ is a superkey. For $\text{studioname}$,
so $\text{studioname}$ is not a superkey and is therefore violates Boyce-Codd Normal Form (BCNF). The gives us the dependency,
To resolve the violation we can decompose movies into,
We can verify, $\text{Movies}_2$ is in BCNF however $\text{Movies}_1$ is not since $\text{president} \to \text{presAddr}$. So the closure is,
and $\text{president} \to \text{presAddr}$ violates $BCNF$. We can decompose the tables further,
Third-normal Form¶
An attribute is considered prime if it is a member of the same key. The functional dependency
is a violating functional dependency if and only if,
- $X$ is not a superkey
- $A$ is not prime
Example
Consider the relation $R(A,B,C)$ with the following functional dependencies
the only violating functional dependency is $C \to B$. We can decompose into the relations,
In this case we could have insertion issues inserting into both relations.