CH 5 Relational Database Design
CH 5 Relational Database Design
2
1. Relational Database Design
• Relational database design requires that we find a “good”
collection of relation schemas
• A bad design may lead to
- Repetition of Information.
• Leads to anomalies
– Loss of information (lossy decomposition).
• Design Goals:
– Avoid redundant data
– Ensure that relationships among attributes are
represented.
– Facilitate the checking of updates for violation of
integrity constraints
Problems of Data Redundancy
4
Problems of Data Redundancy
Modification Anomaly
The same information can be expressed on multiple rows;
therefore modification to the table may result in logical
inconsistencies
5
Problems of Data Redundancy
Insertion Anomaly
There are circumstances in which certain facts cannot be
recorded at all
6
Problems of Data Redundancy
Deletion Anomaly
Under certain circumstances, deletion of data representing certain
facts necessitates deletion of data representing completely different
facts.
8
Functional Dependency
• Functional dependency describes relationship
between attributes.
• For example,
If A and B are attributes of relation R,
B is functionally dependent on A
(denoted A B),
if each value of A in R is associated with exactly
one value of B in R.
9
Functional Dependency
10
Functional Dependency
A B (B is functionally dependent on A)
if each value of A in R is associated with
exactly one value of B in R.
Example Functional Dependency
12
Example Functional Dependency that
holds for all Time
• Consider the values shown in staffNo and
sName attributes of the Staff relation
• The functional dependency is
staffNo → sName sName → staffNo ??
13
Full Functional Dependency
Full functional dependency indicates that if A and B are
attributes of a relation, B is fully functionally dependent on
A, if B is functionally dependent on A, but not on any proper
subset of A.
• Exists in the Staff relation : staffNo, sName → branchNo
• True - each value of (staffNo, sName) is associated with a
single value of branchNo.
• However, branchNo is also functionally dependent on a
subset of (staffNo, sName), namely staffNo. Example above
is a partial dependency.
14
Transitive Dependency
• A transitive dependency in a relation can
potentially cause update anomalies.
R1(AB) R2 (BCD) 17
Properties Of Decomposition
20
Unnormalized Form (UNF)
• A table that contains one or more repeating
groups.
• To create an unnormalized table
– Transform the data from the information source
(e.g. form) into table format with columns and
rows.
21
Any Insertion, Deletion and Modification Anomalies?
22
Which normal form is the table in?
First Normal Form (1NF)
• A relation in which the intersection of each row
and column contains one and only one value.
Not in 1NF
23
UNF to 1NF
• Nominate an attribute or group of attributes to act as
the key for the unnormalized table.
• Identify the repeating group(s) in the unnormalized
table which repeats for the key attribute(s).
24
UNF to 1NF
• Remove the repeating group by
– Entering appropriate data into the empty
columns of rows containing the repeating
data (‘flattening’ the table).
25
‘Flattening the Table’
26
Dependency Diagram
1NF
ORDERLINE
29
Second Normal Form (2NF)
• A relation that is
• in 1NF and
• every non primary-key attribute is
fully functionally dependent on the primary
key.
30
1NF to 2NF
• Identify the primary key for the 1NF relation.
ORDERLINE
34
Third Normal Form (3NF)
• A relation that is
• in 1NF and 2NF and
• in which no non primary-key attribute is
transitively dependent on the primary key.
35
2NF to 3NF
• Identify the primary key in the 2NF relation.
36
2NF (Remove Partial Dependencies)
37
3NF (Remove Transitive Dependencies)
41
1NF to 2NF
1NF (Remove Repeating Group)
42
2NF to 3NF
2NF (Remove Partial Dependencies)
44
2NF to 3NF
2NF (Remove Partial Dependencies)
ProductID -> ProductDescription, ProductFinish, ProductStandardPrice (Partial
Dependencies)