Chapter 4
Chapter 4
Table
Row-1 X
X
Row-2
X
Row-3 X
Row-4
In a relation if a fact is stored more than once ,there is data
redundancy.
Cont’d…
Data redundancy also leads to other issues like:
Insertion , Deletion and Updation problems
Student_table
ID Stu-name Dept Hod Phone-no
Ababa CS Mr. x 0918502888
AAU01
Yadiel CS Mr. x 0918502888
AAU02
John CS Mr. x 0918502888
AAU03
Jonatan CS Mr. x 0918502888
AAU04
Cont’d…
Repetition of data increases the size of databases and leads to
other more issues such as
Insertion anomalies
Updation anomalies
FD = x y
Example
The primary key for this relation is the composite key Emp_ID
and Course_Title.
CustID Name
CustID Salesperson BUT
CustID Region
CustID Salesperson Region
All this is OK Transitive dependency
(2nd NF) (not 3rd NF)
Anomalies
Insertion anomaly because a new salesperson assigned to the
‘North Region’ cannot be entered until a customer has been
assigned, because a value for Cust_ID must be provided to insert a
row in the table
Deletion anomaly because if customer 6837 is deleted from the
table, we lose the information that salesperson Hernandez is
assigned to the ‘East Region’
Modification anomaly because if salesperson Smith is reassigned
to the ‘East Region’, several rows must be changed to reflect that
fact.
Removing transitive
dependencies
This can be done by decomposing SALES into two relations
(see following table.)
Also uses less storage space because the dependent data (such
as Region) do not have to repeat for each customer
Decomposing the SALES relation
Relations in 3NF
Salesperson Region
CustID Name
CustID Salesperson
Student id and subject together form PK. one professor teaches only
one subject, but one subject may have two different professors.
student_id p_id
FD: {A → B, B → C , C → D, D → E }
A+ = {ABCDE}
AD + = {ADBEC}
B + = {BCDE}
Equivalence of Sets of Functional
Dependencies
A set of functional dependencies F is said to cover another set of
functional dependencies E if every FD in E is also in F+; that is, if every
dependency in E can be inferred from F; alternatively, we can say that E is
covered by F.
1. singleton RHS
3. Eliminate redundant
Example
R(A,B,C,D,E)
FD = { A → D, BC → AD, C → B, E → A, E → D}
Step 1 singleton RHS
{ A → D, BC → A, BC → D, C → B, E → A, E → D}
Step 2 extraneous attribute in LHS
BC → A, BC → D (eliminate either B,C in the first and B,C in the second)
{ A → D, BC → A, BC → D, C → B, E → A, E → D}
= { A → D, C → A, BC → D, C → B, E → A, E → D}
{ A → D, C → A, BC → D, C → B, E → A, E → D} eliminate B
= { A → D, C → A, C → D, C → B, E → A, E → D}
Example
FD = { A → D, C → A, C → D, C → B, E → A, E → D}
Step 3: starting from first FD finding the redundant one so we take A→D and if A+
contains the D then we can eliminate other wise we can’t. when computing A + assuming
we eliminate A → D we get = A , we can’t eliminate so this stays and move to the second
one.
{ A → D, C → A, C → D, C → B, E → A, E → D} , compute C +
assuming you
eliminate C → D, C + = CADB , now we can eliminate C → D
In a database, it breaks the table into multiple tables. If the relation has no proper
decomposition, then it may lead to problems like loss of information. Decomposition
is used to eliminate some of the problems of bad design like anomalies,
inconsistencies, and redundancy.
If R decomposed into R1,R2,R3 then all the F1,F2,F3 Union should cover FD in R
Cont’d
3. Non Additive Join Property: ensures that no spurious tuples are generated when
a NATURAL JOIN operation is applied to the relations resulting from the
decomposition.
5. Lossless join property: It is the ability to ensure that any instance of the original
relation can be identified from corresponding instances in the smaller relations.
Cont’d
We must carefully consider the problems associated with NULLs when designing a
A tuple that does not participate in a natural join is called a dangling tuple.
Dangling tuples may indicate a consistency problem in the database.
Example
R (A,B,C,D,E)
FD: {A → B, B → C, C → D, D → A}
Check if these two decompositions preserve FD. R1(A,B,C) and R2(C,D,E) First, find the FD set
for R1
A+ = ABCD (A →BC) Since D IS NOT IN R1 we eliminate D from FD1
B+ = BCDA (B →CA)
C+ = CDAB (C →AB)
AB+ = ABCD (AB →C)
BC+ = BCDA (BC →A) These two are already in the above 3 closure above so FD1 will be
{A →BC, B →CA, C →AB}
Following same process for R2 we get FD2 {C → D, D → C}
Example
Then FD1 U FD2 should be equivalent to FD
i.e FD {A → B, B → C, C → D, D → A} should be a member of
FD1 U FD2 {A →BC, B →CA, C →AB, C → D, D → C}
Therefore, check each FD exist in FD1 U FD2, All the first 3FD exist in the union relation. but what
about the fourth? It does not seem to exist directly so we will check if it exists indirectly by finding
out the determinant D closure
D+ = DCAB since A is a member in closure set of D then we can say D → A is member of FD1 U
FD2 {A →BC, B →CA, C →AB, C → D, D → C}
We can conclude that the decomposed relation preserve dependency.