DBMS Unit-3
DBMS Unit-3
Submitted By:
Dr. Pankaj Jain
1
Informal Design Guidelines
• Semantics of relations and attributes.
4
Figure 14.2 Example relations for the schema of Figure 14.1
5
Figure 14.3 Two relation schemas and their functional dependencies.
Both suffer from update anomalies. (a) The EMP_DEPT relation schema.
(b) The EMP_PROJ relation schema.
6
Figure 14.4 Example relations for the schemas in Figure 14.3 that result from applying
NATURAL JOIN to the relations in Figure 14.2.
7
Figure 14.5 Alternative (bad) representation of the EMP_PROJ relation.
(a) Representing EMP_PROJ of Figure 14.3(b) by two relation schemas: EMP_LOCS and
EMP_PROJ1. (b) Result of projecting the populated relation EMP_PROJ of Figure 14.4 on the
attributes of EMP_LOCS and EMP_PROJ1.
8
Figure 14.5 (continued)
9
Figure 14.6 Result of applying the NATURAL JOIN operation to the tuples above dotted lines in
EMP_PROJ1 and EMP_LOCS, with generated spurious tuples marked by an asterisk.
10
Informal Design Guidelines
• Reducing the null values in tuples. e.g., if 10% of employees have
offices, it is better to have a separate relation, EMP_OFFICE,
rather than an attribute OFFICE_NUMBER in EMPLOYEE.
• Guideline 3: Avoid placing attributes in a base relation whose
values are mostly null.
• Disallowing spurious tuples.
- Spurious tuples: tuples that are not in the original relation but
generated by natural join of decomposed subrelations.
- Example: decompose EMP_PROJ into EMP_LOCS and
EMP_PROJ1. (Fig. 14.5)
- natural join of EMP_LOCS and EMP_PROJ1 results in spurious
tuples. (Fig. 14.6)
• Guideline 4: Design relation schemas so that they can be naturally
JOINed on primary keys or foreign keys in a away that guarantees
no spurious tuples are generated.
11
Functional Dependencies
• A functional dependency, denoted by X Y, between two sets of
attributes X and Y (X and Y are subsets of R) specifies a constraint
on the possible tuples that can form a relation instance r of R: for
any two tuples t1 and t2 in r such that t1[X]= t2[X], we must have
t1[Y]= t2[Y].
13
Functional Dependencies (Cont.)
• Examples.
1. SSN ENAME
2. PNUMBER {PNAME, PLOCATION}
3. {SSN, PNUMBER} HOURS
4. Others?
15
Functional Dependencies (Cont)
• From the FDs:
F = {SSN { ENAME, BDATE, ADDRESS, DNUMBER},
DNUMBER {DNAME, DMGRSSN}}
we can infer the following FDs:
SSN {ENAME, DMGRSSN},
SSN SSN,
DNUMBER DNAME
17
Functional Dependencies (Cont.)
• Closure of X under F, denoted by X+, is the set of all attributes that are
functionally determined by X under F.
• Algorithms for determining X+
X+ := X;
repeat
oldX+ := X+;
for each FD Y Z in F do
if Y X+ then X+ :=X+ Z;
until oldX+ = X+;
• Example:
F = {SSN ENAME, PNUMBER {PNAME, PLOCATION},
{SSN, PNUMBER} HOURS}
{SSN}+ = {SSN, ENAME}
{PNUMBER}+ = ?
{SSN, PNUMBER}+ = ?
18
Functional Dependencies (Cont.)
• Equivalence of sets of FDs.
• F is minimal if
- every dependency in F has a single attribute for its right hand side;
- we cannot remove any FD from F and still have a set of FDs
equivalent to F;
- we cannot replace any FD X A in F with a FD Y A where
Y X and still have a set of FDs equivalent to F.
22
Figure 14.9 Normalizing nested relations into 1NF. (a) Schema of the EMP_PROJ relation with a
“nested relation” PROJS. (b) Example extension of the EMP_PROJ relation showing nested
relations within each tuple.
23
Figure 14.9 (continued)
(c) Decomposing EMP_PROJ into 1NF relations EMP_PROJ1 and EMP_PROJ2 by
propagating the primary key.
24
Figure 14.10 The normalization process. (a) Normalizing EMP_PROJ into 2NF relations. (b)
Normalizing EMP_DEPT into 3NF relations.
25
Normal Forms
• A relation R is in third normal form if for every FD X A that holds on R, either
- X is a superkey of R, or
- A is a prime attribute of R.
(Alternative Def . - No transitive dependencies – If there is a set of attributes Z
that is neither a candidate key nor a subset of any key (primary or candidate)
of R , X Z and Z Y holds.
SSN DMGRSSN is transitive as SSN Dnumber DMGRSSN (Emp-dept) and
dnumber is neither a key nor a subset of key.
• Example. (Fig. 14.10 c)
27
Figure 14.11 (continued)
(c) Decomposing LOTS1 into the 3NF relations LOTS1A and LOTS1B.
(d) Summary of normalization of lots.
28
Figure 14.12 Boyce-Codd normal form. (a) BCNF normalization with the dependency of FD2
being “lost” in the decomposition. (b) A relation R in 3NF but not in BCNF.
29
Figure 14.13 A relation TEACH that is in 3NF but not in BCNF.
30
Normalization
• Database design revisited. Top-down approach – conceptual
design. A more purist way – decomposition.
• Dependency preservation.
(F(R1) F(R2) ……. F(Rm) )+ = F+
where F(R1) is the set of FDs, X Y , in F+ such that
X Y Ri.
• Determine a key
Algorithm 15.4a Find a key K for R.
1. K := R;
2. For each attribute A in K
if (K – {A})+ with-respect-to F contains A then remove A from K;