Primary Key
- A primary key of a relation \(R\) is some chosen key when \(R\) has more than one key.
- Some authors call the different keys candidate keys.
Aim of database design is to get relations that are free of
Two ways to design relations.
Let \(A_1,\dots,A_n,B_1,\dots,B_m\) be attributes of a relation \(R\). The functional dependency (FD) \[A_1 \dots A_n \to B_1 \dots B_m\] means
for any two tuples of any instance of \(R\), if they agree on all attributes in \(\{ A_1, \dots, A_n \}\) then they also agree on all attributes in \(\{ B_1, \dots, B_m \}\).
In such a case, we say that \(\{A_1, \dots, A_n\}\) functionally determines \(\{B_1, \dots, B_m\}\).
Splitting/Combining Rule \[A_1 \dots A_n \to B_1\dots B_m\] is equivalent to the conjunction of all these \(m\) FD’s \[A_1\dots A_n \to B_1\] \[\vdots\] \[A_1\dots A_n \to B_m\]
Trivial Dependency An FD \(A_1\dots A_n \to B_1\dots B_m\) is said to be trivial if \(\{ B_1,\dots, B_m\} \subseteq \{A_1,\dots, A_n\}\). Every trivial dependency is true.
In the relation
Movies1(title, year, length, genre, studioName, starName)
we have
title year \(\to\) length genre studioName
However, it is false that
title, year \(\to\) starName
Let \(S\) and \(T\) be sets of FD’s on the same relation \(R\).
The FD \(A_1 \dots A_n \to B_1\dots B_m\) is equilvalent to the FD \(A_1\dots A_n \to C_1\dots C_k\), where the \(C\)’s are all of \(B\)’s that are not in \(A\).
Let \(A = \{ A_1, \cdots, A_n \}\) be a subset of attributes of a fixed relation \(R\), and let \(S\) be a set of FD’s that \(R\) satisfies. The closure of \(A\) with respect to \(S\) is a set of all attributes \(B\) such that the FD \(A_1\dots A_n \to B\) follows from \(S\). It is denoted \(A^+\).
Input: 1. Attributes \(A_1,\dots,A_n\) of relation \(R\)
2. a set \(S\) of FD’s on \(R\)
Return: The positive closure of \(\{A_1,\dots,A_n\}\) with respect to \(S\).
split S;
X := { A1,..., An };
repeat
if there exists a subset { B1,...,Bn } of X
having B1...Bn → C in S with C not in X then
X := X ∪ {C}
until (no such subset is found);
return X;
Problem: Consider the relation \(R(A, B, C, D, E, F)\) and set \(S = \{ AB\to C,\ BC\to AD,\ D\to E,\ CF\to B \}\) of FD’s. Compute \(\{A,B\}^+\).
Answer: \(\{A,B\}^+ = \{ A, B, C, D, E \}\).
The Transitivity Rule states that
If \[A_1\dots A_n \to B_1\dots B_m\] and \[B_1\dots B_m \to C_1\dots C_k\] then \[A_1\dots A_n \to C_1\dots C_k.\]
It can be proved by considering \(\{A_1,\dots,A_n\}^+\).
Armstrong’s Axioms is a set of inference rules that can be used to derive any FD that follows from a given set of FD’s. There are three axioms in the set.
(See William Ward Armstrong: Dependency Structures of Data Base Relationships, page 580-583, IFIP Congress, 1974.)
Let \(S\) be a set of FD’s.
Problem: Let \(R(A,B,C)\) be a relation satisfying the set of FD’s \(S = \{\) \(A\to B\), \(A\to C\), \(B\to A\), \(B\to C\), \(C\to A\), \(C\to B\) \(\}\).
Input: Relations \(R\) and \(R_1 = \pi_L(R)\) and a set of FD’s on \(R\).
Return: A minimal basis for the set of all FD’s that hold in \(R_1\) as a result of FD’s on \(R\).
T := empty set;
for each subset of attributes X of R_1 do {
compute X+;
add to T all nontrivial FD's X → A such that
A is both in X+ and an attribute of R_1;
}
repeat
if there's an FD F in T that follows from
the other FD's in T then remove F from T;
let Y → B be an FD in T with # attributes in Y ≥ 2
and let Z be Y with one of the attributes removed;
if Z → B follows from the FD's in T then
replace Y → B by Z → B;
until (no more changes to T can be made);
return T;
Problem: Let \(R(A,B,C,D)\) be a relation that satisfies a set of FD’s \(S = \{ A\to B,\ B\to C,\ C\to D \}\). Find a projection of \(S\) onto \(R_1(A,C,D)\).
Answer: The set of FD’s \(S_1 = \{ A\to C,\ C\to D\}\) is a minimal basis for the projection.