5 RelationalDesignTheory
5 RelationalDesignTheory
Database
Design
COMP 353/453
Database Programming
Prof. Silva
These slides were prepared by Prof. Silva adapting the slides from Fundamentals of Database Systems (Elmasri and Navathe) and Understanding
1
Relational Database Query Languages (Dietrich)
Relational Database Design
Undesirable Properties
• Repetition of information
• Inability to represent certain information
• Loss of information
Desirable Properties
• No Repetition of Information (Normal Forms)
• Dependency Preservation
• Lossless-join Decomposition
2
Functional Dependencies - Definition
An FD XY is trivial if Y X
Note: if K is a superkey of R, then KR
3
Functional Dependencies - Examples
4
More on Functional Dependencies
5
Functional Dependencies: Company Training Courses
Enterprise
Most of the FDs for an enterprise are already included in the conceptual
model. Using the ER diagram and the semantics of the enterprise, give
the FDs for the company training courses example.
1
mgr 1
ID DNUM
NAME emp dept
N 1 DNAME
SAL M
works
DATE takes
N
CRSID INST
course
CNAME LENGTH
6
Theory of Functional Dependencies
ZBAB Augmentation(f1,B)
ABAX Augmentation(f2, A)
ZBAX Transitivity(ZBAB, ABAX)
ZBY Transitivity(ZBAX, f3)
Algorithm: compute X+
Input: F - set of FDs
X - set of Attributes
Output: X+ - set of attributes
Result := X; /*reflexivity */
while (changes to Result) do
for each FD YZ in F do
if Y Result then Result := Result Z; /* transitivity */
X+ := Result;
9
Example: Attribute Closure
Is ZBY in F+?
Equivalently, is Y in (ZB)+?
Result: ZB Given
ZBA f1
ZBAX f2
ZBAXY f3
Yes!
10
Decomposition
Let C be a set of constraints on the DB. A decomposition {R1, R2, ..., Rn} of a
relation scheme U is a lossless-join decomposition if for all relations u on
scheme U that are legal under C
n
u = _ Ri (u)
i=1
12
Lossless-join Decomposition – Supplier Example
lossless-join decomposition
r1 = suppaddr(SNAME, SADDR)
r2 = suppitem(SNAME, ITEM, PRICE)
13
Lossless-join Decomposition - Addresses Example
Assumption: a ZIP
2. addresses(NAME, CITY, ZIP) F={f1, f2} code covers only 1 city
15
Desirable Properties: Dependency
Preservation
"Update validation without computation of joins"
In general, F F'.
A dependency preserving decomposition has the property that (F') + = F+,
i.e., every dependency in F is logically implied by F'.
16
Testing Dependency Preservation
compute F+
For each scheme Ri in D do
Fi := the restriction of F+ to Ri;
n
F := F j
j=1
compute(F')+
return((F')+ = F+)
... Not always necessary to use this algorithm, we can check that F'=F or
that each FD in F - F' is logically implied by F'
17
Dependency Preservation - Suppliers
Example
1. suppliers(SNAME, SADDR, ITEM, PRICE)
F' = F,
dependency preserving
18
Dependency Preservation - Addresses
Example
Assumption: a ZIP
2. addresses(NAME, CITY, ZIP)
code covers only 1 city
(a) F = {f1: NAMEZIP f2: ZIPCITY}
R1 = {NAME, CITY} F1 =
R2 = {ZIP, CITY} F2 = {f2}
F' = {f2} F - F' = {f1}
Is f1 logically implied by F' ?
No, NOT dependency preserving
(b) F ={f1: NAME ZIP, f2: ZIP CITY}
R1 = {NAME, ZIP} F1 = {f1}
R2 = {CITY, ZIP} F2 = {f2}
F' = F, dependency preserving
Note:
1. A decomposition may have a lossless-join w.r.t. F yet not preserve F.
2. A decomposition could preserve F yet not have a lossless-join.
19
Desirable Properties: No Repetition of
Information
Normal forms represent degrees of redundancy ...
UNNORMALIZED 1NF
20
Normal Forms: 2NF
A relation scheme R is in 2NF if each attr A in R either
• appears in a candidate key, or
• is not dependent on any proper subset of any candidate key
(is dependent on the whole of every candidate key)
21
Normal Forms: 3NF
A relation scheme R is in 3NF if for all FDs that hold on R of the form XY,
where X R and Y R, at least one of the following holds:
• XY is a trivial FD
• X is a superkey
• Y is contained in a candidate key for R
24
Design Goals
• Goal for a relational database design is:
• BCNF (no redundant information)
• Lossless join
• Dependency preservation
• If we cannot achieve this, we accept:
• 3NF (possible repetition of information)
• Lossless join
• Dependency preservation
25