UNIT 3 DBMS R23
UNIT 3 DBMS R23
Smartzworld.com Smartworld.asia
UNIT-III
----------------------------------------------------------------------------------------------------------------
2. Functional Dependencies
3. Normal Forms
4. Decompositions
96 | P a g e
Smartzworld.com Smartworld.asia
• Main refinement technique: decomposition (replacing ABCD with, say, AB and BCD,
• Storing the same information redundantly, that is, in more than one place within a
• Consider a relation obtained by translating a variant of the Hourly Emps entity set
97 | P a g e
Smartzworld.com Smartworld.asia
Ex: Hourly Emps(ssn, name, lot, rating, hourly wages, hours worked)
• The key for Hourly Emps is ssn. In addition, suppose that the hourly wages attribute
• is determined by the rating attribute. That is, for a given rating value, there is only
3. Decompositions:
• Functional dependencies (ICs) can be used to identify such situations and to suggest
• The essential idea is that many problems arising from redundancy can be addressed by
• Each of the smaller relations contains a subset of the attributes of the original relation.
• We refer to this process as decomposition of the larger relation into the smaller relations
• We can deal with the redundancy in Hourly Emps by decomposing it into two relations:
8 10
5 7
98 | P a g e
Smartzworld.com Smartworld.asia
123-22-3666 Attishoo 48 8 40
231-31-5368 Smiley 22 8 30
131-24-3650 Smethurst 35 5 30
434-26-3751 Guldu 35 5 32
612-67-4134 Madayan 35 8 40
• Unless we are careful, decomposing a relation schema can create more problems than it
solves.
• To help with the rst question, several normal forms have been proposed for relations.
• If a relation schema is in one of these normal forms, we know that certain kinds of
99 | P a g e
Smartzworld.com Smartworld.asia
• A functional dependency X Y holds over relation R if, for every allowable instance r
of R:
– i.e., given two tuples in r, if the X values agree, then the Y values must also
100 | P a g e
Smartzworld.com Smartworld.asia
• Notation: We will denote this relation schema by listing the attributes: SNLRWH
101 | P a g e
Smartzworld.com Smartworld.asia
• Suppose that we have entity sets Parts, Suppliers, and Departments, as well as a
relationship set Contracts that involves all of them. We refer to the schema for
Contracts as CQPSD. A contract with contract id
• C species that a supplier S will supply some quantity Q of a part P to a department D.
• We might have a policy that a department purchases at most one part from any given
supplier.
• Thus, if there are several contracts between the same supplier and department,
• we know that the same part must be involved in all of them. This constraint is an FD,
DS ! P.
– Reflexivity: If X Y, then Y X
102 | P a g e
Smartzworld.com Smartworld.asia
– JP C
– D P
• SD P implies SDJ JP
• Computing the closure of a set of FDs can be expensive. (Size of closure is exponential
in # attrs!)
An efficient check:
– Check if Y is in
• Does F = {A B, B C, C D E } imply A E?
• The set of all FDs implied by a given set F of FDs is called the closure of F and is
denoted as F+.
• An important question is how we can infer, or compute, the closure of a given set F of
103 | P a g e
Smartzworld.com Smartworld.asia
FDs.
• The following three rules, called Armstrong's Axioms, can be applied repeatedly to
• Armstrong's Axioms are sound in that they generate only FDs in F+ when applied to a
set F of FDs.
• They are complete in that repeated application of these rules will generate all FDs in
• These additional rules are not essential; their soundness can be proved using
Armstrong's Axioms.
Attribute Closure
set F of FDs,
• we can do so eciently without computing F+. We rst compute the attribute closure X+
with respect to F,
• which is the set of attributes A such that X → A can be inferred using the Armstrong
104 | P a g e
Smartzworld.com Smartworld.asia
Axioms.
• closure = X;
6. Normal Forms:
• The normal forms based on FDs are rst normal form (1NF), second normal form (2NF),
• These forms have increasingly restrictive requirements: Every relation in BCNF is also
in 3NF,
• every relation in 3NF is also in 2NF, and every relation in 2NF is in 1NF.
• A relation
• is in first normal form if every field contains only atomic values, that is, not lists or
sets.
• Although some of the newer database systems are relaxing this requirement
105 | P a g e
Smartzworld.com Smartworld.asia
Normal Forms
• Returning to the issue of schema refinement, the first question to ask is whether any
refinement is needed!
• If a relation is in a certain normal form (BCNF, 3NF etc.), it is known that certain kinds
• Given A B: Several tuples could have the same A value, and if so,
values)
• a relation R in 2NF if and only if it is in 1NF and every nonkey column depends
106 | P a g e
Smartzworld.com Smartworld.asia
SSN ENAME
PNO PNAME
• a relation R in 3NF if and only if it is in 2NF and every nonkey column does not
107 | P a g e
Smartzworld.com Smartworld.asia
• In other words, R is in BCNF if the only non-trivial FDs that hold over R are key
constraints.
cannot infer the A value in one tuple from the A value in the other.
Smartzworld.com Smartworld.asia
10.BCNF:
Example Decomposition
109 | P a g e
Smartzworld.com Smartworld.asia
projections of these tuples onto SNLRH and RW, are there any potential problems that
we should be aware of?
Problems with Decompositions
decomposed relations.
• Decomposition of R into X and Y is lossless-join w.r.t. a set of FDs F if, for every
– (r) (r) = r
– In general, the other direction does not hold! If it does, the decomposition is
lossless-join.
• It is essential that all decompositions used to deal with redundancy be lossless! (Avoids
110 | P a g e
Smartzworld.com Smartworld.asia
Problem (2).)
Y and on Z, then all FDs that were given to hold on R must also hold. (Avoids
Problem (3).)
111 | P a g e
Smartzworld.com Smartworld.asia
if (FX union FY ) + = F +
and XY.
– Repeated application of this idea will give us a collection of relations that are in
• In general, several dependencies may cause violation of BCNF. The order in which we
112 | P a g e
Smartzworld.com Smartworld.asia
– e.g., CSZ, CS Z, Z C
preserving decomposition.
• Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a
– Problem is that XY may violate 3NF! e.g., consider the addition of CJP to
• Refinement: Instead of the given set of FDs F, use a minimal cover for F.
• Consider the Hourly Emps relation again. The constraint that attribute ssn is a key can
be expressed as an FD:
• { ssn }-> { ssn, name, lot, rating, hourly wages, hours worked}
113 | P a g e
Smartzworld.com Smartworld.asia
• For brevity, we will write this FD as S -> SNLRWH, using a single letter to denote each
attribute
• In addition, the constraint that the hourly wages attribute is determined by the rating
attribute is an
FD: R -> W.
• The previous example illustrated how FDs can help to rene the subjective decisions
• but one could argue that the best possible ER diagram would have led to the same nal
set of relations.
• Our next example shows how FD information can lead to a set of relations that
• in particular, it shows that attributes can easily be associated with the `wrong' entity set
during ER design.
• The ER diagram shows a relationship set called Works In that is similar to the Works
In relationship set
• Using the key constraint, we can translate this ER diagram into two relations:
114 | P a g e
Smartzworld.com Smartworld.asia
• Let Reserves contain attributes S, B, and D as before, indicating that sailor S has a
• In addition, let there be an attribute C denoting the credit card to which the reservation
is charged.
• Suppose that every sailor uses a unique credit card for reservations. This constraint is
expressed by the FD
S -> C. This constraint indicates that in relation Reserves, we store the credit card number
15.Multivalued Dependencies:
• Suppose that we have a relation with attributes course, teacher, and book, which we
denote as CTB.
• The meaning of a tuple is that teacher T can teach course C, and book B is a
• There are no FDs; the key is CTB. However, the recommended texts for a course are
115 | P a g e
Smartzworld.com Smartworld.asia
• The relation schema CTB is in BCNF; thus we would not consider decomposing it
• There is redundancy. The fact that Green can teach Physics101 is recorded once per
recommended text for the course. Similarly, the fact that Optics is a text for Physics101
is recorded once per potential teacher.
• Let R be a relation schema and let X and Y be subsets of the attributes of R. Intuitively,
• The redundancy in this example is due to the constraint that the texts for a course are
should model this situation using two binary relationship sets, Instructors with attributes
CT and Text with attributes CB.
• Because these are two essentially independent relationships, modeling them with a
116 | P a g e
Smartzworld.com Smartworld.asia
WX →→ YZ.
X →→ (Z − Y ).
• R is said to be in fourth normal form (4NF) if for every MVD X →→Y that holds over
• Y subset of X or XY = R, or
• X is a superkey.
17.Join Dependencies:
XY,X(R−Y)}
• As an example, in the CTB relation, the MVD C ->->T can be expressed as the join
• Unlike FDs and MVDs, there is no set of sound and complete inference rules for JDs.
• A relation schema R is said to be in fth normal form (5NF) if for every JD ∞{ R1,….
• Ri = R for some i, or
117 | P a g e
Smartzworld.com Smartworld.asia
• The JD is implied by the set of those FDs over R in which the left side is a key for R.
• The following result, also due to Date and Fagin, identies conditions|again, detected
• If a relation schema is in 3NF and each of its keys consists of a single attribute,it is also
in 5NF.
19.Inclusion Dependencies:
• MVDs and JDs can be used to guide database design, as we have seen, although they
are less common than FDs and harder to recognize and reason about.
• In contrast, inclusion dependencies are very intuitive and quite common. However, they
• The main point to bear in mind is that we should not split groups of attributes that
• Most inclusion dependencies in practice are key-based, that is, involve only keys.
118 | P a g e