Firashvsor
Firashvsor
Unit – III
LEARNING MATERIAL
DATABASE DESIGN
1. Functional Dependencies
A Functional Dependency describes the relationship between the
attributes within a relation.
An attribute is functionally dependent on another attribute if we can use the
value of one attribute to determine the value of another attribute.
Formally, functional dependency is defined as;
{Student#, Course#} à
Grade
This type of dependency is called as functional dependency. In the above
example Grade is functionally dependent on {Student#, Course#}.
Other functional dependencies in the above example are:
Student# à StudName
Course# à CourseName
As an another example, consider the relation R(A,B) with the following instance of R.
A B
1 4
1 5
3 7
On this instance, the functional dependency A B does not hold because, for
the value 1 of A, it is not determining exactly one value; rather it is
determining two values (4 and 5).
But the functional dependency B A holds on this relation.
As another example, consider the following relation Employee.
Employee relation
The functional dependencies that holds on this relation are;
EmpID EmpName
EmpID DeptID
DeptID DeptName
Here,
Course# à Iname and Iname à Room# so Course# à Room#
Reflexivity: If then X Y.
Augmentation: If X Y, then XZ YZ for any Z.
Transitivity: If X Y and Y Z, then X Z.
It is helpful to use some additional rules while reasoning about F+.
Union: If X Y and X Z, then X YZ.
Decomposition: If X YZ, then X Y and X Z.
Example
Let F be the following set of functional dependencies: {AB→CD, B→DE,
C→F, E→G, A→B }. Use Armstrong’s axioms to show that {A→FG } is
logically implied by F.
3 AB CD Given
4 A CD 2,3, Transitivity
5 B DE Given
6 A DE 1,5, Transitivity
7 A ACD 4, Augmentation
10 A CE 9, Trivial dependency
11 CF Given
12 CE FE 11, Augmentation
13 EG Given
14 FE FG 13, Augmentation
15 CE FG 12,14, Transitivity
16 A FG 10,15, Transitivity
Example1 for F+
Assume that there are 4 attributes A, B, C, D, and that
F = { A B, B C }. Then, F+ includes all the following FDs:
F+ = { A A, A B, A C, B B, B C, C C, D D, AB A,
AB B, AB C, AC A, AC B, AC C, AD A, AD B,
AD C, AD D, BC B, BC C, BD B, BD C, BD D,
CD C, CD D, ABC A, ABC B, ABC C, ABD A,
ABD B, ABD C, ABD D, BCD B, BCD C, BCD D,
ABCD A, ABCD B, ABCD C, ABCD D }
Example 2 for F+
Let R = (A,B,C,G,H,I) and let F = { AB, AC, CG H, CG I, B H } then
some members of F+ are;
A B, B H then A H [Transitivity rule]
A B, A C then A BC [Union rule]
CG H, CG I then CG HI[Union rule]
A H, A BC then A BCH [Union rule]
A+ = {ABCH} ≠ R
G+ = {G} ≠ R
Since, (AG)+ = R (i.e. AG determines all attributes of R) and no proper
subset of {AG} is a candidate key for R So, AG is a candidate key for R.
Example 3.3
Consider the relation R = {A,B,C,D,E,F,G,H} with a set of FDs F={CDàA, ECàH,
GHBàAB, CàD, EGàA, HàB, BEàCD, ECàB}. Find all the candidate keys of R.
Sol: Tricks for finding all the candidate keys
If an attribute never appears on the RHS of any FD, it must be part of the
key.
If an attribute never appears on the LHS of any FD, but appears on the RHS
of any FD, it must not be part of any key.
Based on the above tricks, we notice that:
o EFG never appear on RHS of any FD. So, EFG must be part of ANY key
of R.
o A never appears on LHS of any FD, but appears on RHS of some FD.
So, A is not part of ANY key of R.
o We now see if EFG is itself a key…
o EFG+ = EFGA ≠ R; So, EFG alone is not key.
Example 3.4
Consider the relation R(X, Y, Z, V, W) which satisfies the following functional
dependencies.
F = { XY Z, YZ V, ZV W, VW X, XW Y }
Which of the following functional dependencies are also satisfied by the relation
R?
i) XZ V ii) YZV X iii) Z W iv) X Z
Sol: To check whether these functional dependencies hold on R, we need to
compute the attribute closure of the attributes lying on the LHS of FDs. If
attribute closure contains the attributes on RHS respectively, then the
corresponding FD holds on R.
i) (XZ)+ = { XZ }, V not in { XZ }. So, XZ V does not hold on R.
ii) (YZV)+ = {YZVWX}, X in {YZVWX}. So, YZV X holds on R.
iii) Z+ = {Z}, W not in { Z }. So, Z W does not hold on R.
iv) X+ = {X}, Z not in { X }. So, X Z does not hold on R.
4. Canonical Cover
Sets of functional dependencies may have redundant dependencies that can
be inferred from the others.
For example: A C is redundant in: {A B, B C, A C}
Parts of a functional dependency may be redundant.
For example, on RHS: { A B, B C, A CD } can be simplified to
{ A B, B C, A D }
Because, in A CD, A C can be obtained from
AB and BC then AC.
Hence, AC is considered as redundant.
Department of Information Technology A.Y.2019-20 II-II GEC Page 8
Database Management Systems UNIT-III
Canonical Cover
A canonical cover for F is a set of dependencies Fc such that
o F logically implies all dependencies in Fc, and
o Fc logically implies all dependencies in F, and
o No functional dependency in Fc contains an extraneous attribute, and
o Each left side of functional dependency in Fc is unique
To compute a canonical cover for F:
Note: Union rule may become applicable after some extraneous attributes
have been deleted, so it has to be re-applied.
Example 4.1
Let R = (A,B,C) and F = { A BC, B C, A B, AB C }. Compute canonical
cover for R.
Sol:
Combine A BC and A B into A BC
o Set is now {A BC, B C, AB C}
A is extraneous in AB C
o Check if the result of deleting A from AB C is implied by the other
dependencies.
o Yes: in fact, B C is already present!
o Set is now {A BC, B C}
C is extraneous in A BC
o Check if A C is logically implied by A B and the other dependencies.
o Yes: using transitivity on A B and B C.
5. Properties of Decomposition
Example 5.1
Consider Supplier_Parts schema:
Supplier_Parts(S#, Sname, City, P#, Qty)
Having dependencies: S# → Sname, S# → City, (S#, P#) → Qty
Department of Information Technology A.Y.2019-20 II-II GEC Page 11
Database Management Systems UNIT-III
2 Steve Boston 20 10
5 Nick NY 400 40
5 Nick NY 301 10
2 Steve Boston 10 20 10
5 Nick NY 40 400 40
5 Nick NY 10 301 10
Natural join
2 Steve Boston 20 10
5 Nick NY 400 40
Extra tuples
5 Nick NY 20 10
5 Nick NY 301 10
After natural join, we got two extra tuples. Therefore, the decomposition as:
Supplier(S#, Sname, City, Qty); Parts(P#, Qty) is a lossy
decomposition.
This is because; we decomposed Supplier_Parts relation on the common
attribute Qty which is not a candidate key for Supplier or Parts.
Decompositions not based on candidate keys leads to lossy decompositions.
This decomposition does not preserve {S#,P#} Qty.
Example 5.2
Consider schema: Supplier_Parts(S#, Sname, City, P#, Qty)
Having dependencies: S# → Sname, S# → City, (S#, P#) → Qty
Decomposed as: Supplier(S#, Sname, City); Parts(S#, P#, Qty)
2 Steve Boston 20 10
5 Nick NY 400 40
5 Nick NY 301 10
2 Steve Boston 2 20 10
5 Nick NY 5 400 40
5 Nick NY 5 301 10
Natural join
2 Steve Boston 20 10
5 Nick NY 400 40
5 Nick NY 301 10
After natural join, we get back the original relation. Therefore, the
decomposition as: Supplier(S#, Sname, City); Parts(S#, P#, Qty) is a
lossless decomposition.
Here, the common attribute S# is a candidate key in Supplier.
This decomposition preserves all dependencies.
Example 5.3
Let R = (A, B, C) and let F = { AB, BC }. Check if the decomposition of R into
D is lossless?
i) D = { R1(A, B), R2(B, C) } ii) D = { R1(A, B), R2(A, C) }
Sol: i) Check R1 ∩ R2 R1 or R1 ∩ R2 R2
R1 ∩ R2 = (A, B) ∩ (B, C) = B and B+ = BC = R2
Hence, the decomposition is lossless.
ii) R1 ∩ R2 = (A, B) ∩ (A, C) = A and A+ = AB = R1
Hence, the decomposition is lossless.
Example 5.4
Let R = (ABCDEF) and F = { A→BCD, A→EF, BC→AD, BC→E, BC→F, B→F, D→E }.
Let the decomposition D = { ABCD, BF, DE }. Check whether this decomposition
is dependency preserving.
Sol: On projections
BCAD
Need to check for: A→BCD, A→EF, BC→AD, BC→E, BC→F, B→F, D→E
(BC)+/F1 = ABCD; (ABCD)+/F2 = ABCDF; (ABCDF)+/F3 = ABCDEF. Preserves
BC→E, BC→F
(A)+/F1 = ABCD; (ABCD)+/F2 = ABCDF; (ABCDF)+/F3 = ABCDEF. Preserves
A→EF
Since, this decomposition preserves all FDs in F So, this decomposition is
dependency preserving.
Example 5.5
Sol: On projections
R2(CDE
R1(AB) R3(EF)
)
CD EF
DE
CourseI
FID Fname HireDate CourseName
D
Faculty_Course table
Suppose a new faculty called Dr. Nick has joined the institution and has not
yet assigned the course. Then it is not possible to insert this new faculty to
Faculty_Course table because it violates the primary key constraint.
(because CourseID is null in this case)(Primary key for this table is {FacultyID,
CourseID}
This table is not in 1NF because; the attribute Content does not contain
atomic values.
To convert it into 1NF table, we rearrange the table as shown below (i.e.
create a row for each value of Content).
The resulting two relations are in 2NF because there are no partial
dependencies in these relations.
Department of Information Technology A.Y.2019-20 II-II GEC Page 19
Database Management Systems UNIT-III
Example 6.1
Let R = ABCDEFGH and F = {A→B, ABCD→E, EF→GH, ACDF→EG}. Find the 3NF
decompositions of R.
Sol: Compute Canonical Cover (Fc)
Make RHS a single attribute: {A→B, ABCD→E, EF→G, EF→H, ACDF→E,
ACDF→G}.
Minimize LHS: ACD→E instead of ABCD→E
Eliminate redundant FDs
o ACDF→G be removed
Department of Information Technology A.Y.2019-20 II-II GEC Page 20
Database Management Systems UNIT-III
o ACDF→E be removed
Fc = {A→B, ACD→E, EF→G, EF→H}
Candidate key = ACDF
3NF Decomposition = {AB, ACDE, EFG, EFH} U {ACDF}
This table has two candidate keys – {Student#, Course#} and {EmailID,
Course#}.
This table is in 3NF because it has no partial and transitive dependencies
between key and non-key attributes.
But this table is not in BCNF because all determinants are not candidate keys.
This can be observed from the following FDs;
o {Student#, Course#} à Marks
o {EmailID, Course#} à Marks
o Student# à EmailID
o EmailID à Student#
To make this table into BCNF compliant, we need to decompose the Result
table into two tables as shown below;
Example 6.2
Let R = (A, B, C ) and F = {AB, BC}. Find BCNF decompositions of R.
Sol: Key = {A}
Hence, R is not in BCNF (Because in BC, B is not the key)
BCNF decompositions: R1= (A, B) and R2 = (B, C)
Redundancy is high as
2 0% redundancy
compared to BCNF
A dependency X → Y is
allowed in 3NF if A dependency X → Y is
3
X is a super key or Y is a allowed if X is a super key
part of some key.
Course(C Teacher(
Book(B)
) T)
Physics10
Green Mechanics
1
Physics10
Green Optics
1
Physics10
Brown Mechanics
1
Physics10
Brown Optics
1
o Course Teacher
o Teacher Book
As another example, consider the following relation Person.
Phones( Dogs_Like(
Man(M)
P) D)
M1 P1 D1
M1 P2 D2
M2 P3 D2
M1 P1 D2
M1 P2 D1
S1 A C1 C
S1 A C2 B
S2 B C1 C
S2 B C2 B
Student_Course table