IT 220 Unit 4 Relational Database Design
IT 220 Unit 4 Relational Database Design
Topics
• Informal Design Guidelines for Relational Schemas;
• Functional Dependencies
• Normal Forms Based on Primary Keys;
• First, Second and Third Normal Forms; Boyce-Codd Normal Form; Multivalued
Dependency and Fourth Normal Form;
• Properties of Relational Decomposition.
1
7/30/2024
Loss of information.
2
7/30/2024
Anomalies
Anomalies are problems that can occur in poorly planned, un-
normalised databases where all the data is stored in one table (a flat-
file database).
Insert anomaly: insertion anomaly occurs in database when certain
attributes cannot be inserted without the presence of other.
Delete anomaly: Certain information are loss due to the delete of
other values.
Update anomaly: anomalies occur during the time of recording the
data in any one table causes a partial update or data redundant.
Table Design
Teach_id Teacher_name Department Course_name
T1010 Mr. R K Agrawal Science & Technology Physics
T1011 Mr. Shyam Krishna Mahat Management Economics
T1012 Mr. R K Agrawal Science & Technology Biology
T1013 Ms. Anjila Bhatta Information Technology Java Programming
Insertion anomalies: If new teacher is added, but s/he is not assign to any
department or any course and if null entries are not allowed in database then
insertion anomalies occur.
Deletion anomalies: If management department is deleted then records of
teacher as well as course name also deleted from database.
Update anomalies: If department assign to R K Agrawal is an error, then it need
to updated at two places to make consistency.
3
7/30/2024
Functional Dependencies
Functional dependency is a relationship that exists
when one attribute uniquely determines another
attribute.
Functional dependency (FD) is a set of constraints
between two attributes in a relation. Functional
dependency says that if two tuples have same values
for attributes A1, A2,..., And, then those two tuples
must have to have same values for attributes B1, B2,
..., Bn.
If A is the determinant and B is the determined then we
say that A functionally determines B and graphically
represent this as A B. The symbols AB, can also be
expressed as B is functionally determined by A.
Functional Dependencies
An important property of a functional dependency is Armstrong’s
axiom
In a relation, R, with three attributes (X, Y, Z) Armstrong’s axiom holds
true if the following conditions are satisfied:
Axiom of Transivity: If X->Y and Y->Z, then X->Z
Axiom of Reflexivity (Subset Property): If Y is a subset of X, then X->Y
Axiom of Augmentation: If X->Y, then XZ->YZ
To make life easier we can use some additional rules, derivable from
Armstrong's Axioms:
Union rule: if X->Y and Y->Z , then X->YZ holds.
Decomposition rule: if X->YZ holds, then X->Y and X->Z both hold.
Pseudotransitivity rule: if X->Y holds, and AY->Z holds, then XA->Z holds.
4
7/30/2024
FD Example
Instructor_id name phone
1010 Ram Krishna Karki 9851112130
1020 Subodh Satyal 9801112134
1030 Smiriti Shah 9841424344
1040 Ram Krishna Karki 9803214315
10
5
7/30/2024
Example of FD
R = (A, B, C, G, H, I)
Given F = { A → B ,A → C, CG → H, CG → I, B → H}
some members of F+
A → H : by transitivity from A → B and B → H
AG → I : by augmenting A → C with G, to get AG → CG and then transitivity with
CG → I
CG → HI :from CG → H and CG → I : “union rule” can be inferred from definition of
functional dependencies, or:
(1) augmentation of CG → I to infer CG → CGI, (2) augmentation of CG → H to infer
CGI → HI, and then (3) transitivity.
11
Procedure to Compute F+
F+ = F
repeat
for each functional dependency f in F+
apply reflexivity and augmentation rules on f
add the resulting functional dependencies to F+
for each pair of functional dependencies f1 and f2 in F+
if f1 and f2 can be combined using transitivity
add the resulting functional dependency to F+
until F+ does not change any further
12
6
7/30/2024
13
14
7
7/30/2024
15
Find (C,D)+
Find (B,C)+
16
8
7/30/2024
Home Work
17
Keys
Candidate Key: Candidate Key is minimal set of
attributes of a relation which can be used to identify a
tuple uniquely.
Note: A candidate key may or may not be a primary key.
Super Key: Super Key is set of attributes of a relation
which can be used to identify a tuple uniquely.
Note: A Candidate key is always super key but not vice
versa.
18
9
7/30/2024
19
20
10
7/30/2024
Decomposition
Decomposition in DBMS removes redundancy, anomalies and
inconsistencies from a database by dividing the table into multiple
tables.
Lossy Decomposition: when a relation is decomposed into two or more
relational schemas, the loss of information is unavoidable when the
original relation is retrieved.
21
22
11
7/30/2024
A B C A B B C
1 A 1 1 A
2 B 2 2 B
r A,B(r) B,C(r)
A B C
A (r) B (r)
1 A
2 B
23
Normalization
Normalization is a technique of organizing the data in the database.
Systematic approach of decomposing tables to eliminate data
redundancy and undesirable characteristics like Insertion, Update and
Deletion Anomalies.
Normalization is the process of removing anomalies from the database
table.
Normalization removes the undesirable properties by working through
a series of stages of called Normal forms.
Such Normal forms are: 1NF, 2NF, 3NF, BCNF, 4NF and 5NF
Normalization is used for mainly two purpose
Eliminating redundant (useless) data.
Ensuring data dependencies make sense i.e, data is logically stored.
24
12
7/30/2024
Functional Dependency:
• If an attribute's (A) value is known on the basis of another attribute
B, then A is said to be functionally dependent on B.
Symbolically, FD: B -> A.
• Example, Roll -> Name (i.e. if roll is known name can be known)
• If we know the value of primary key, then we can find out the another
attributes.
• Functionally dependencies are of following types:
• Trivial & Non-Trivial Functional Dependency
• Partial Dependency
• Transitivity Dependency
25
26
13
7/30/2024
27
28
14
7/30/2024
Transitivity Dependency:
It is a type of functional dependency where a non key attribute
determines another non key attribute.
29
Given table is not in 1NF because knowledge has more than one value.
Solution : split table
30
15
7/30/2024
Cont..
eid Name Job Dep_id eid Knowledge
31
32
16
7/30/2024
33
34
17
7/30/2024
35
36
18
7/30/2024
37
38
19
7/30/2024
39
40
20
7/30/2024
Cont…
A relation is in BCNF if and only if every determinant is a candidate key.
Consider the following table :
41
Cont…
Ecode + ProjCode is the primary key. Name + ProjCode should be chosen
as primary key and hence is a candidate key.
Hours is functionally dependent on Ecode+ProjCode.
Hours is also functionally dependent on name+ProjCode.
Name is functionally dependent on Ecode.
Ecode is functionally dependent on Name.
42
21
7/30/2024
Cont..
Ecode and Name are determinants since they are functionally dependent on each
other. However, they are not candidate keys by themselves. As per BCNF, the
determinants have to be candidate keys.
Guidelines for converting a table to BCNF:
Find and remove the overlapping candidate keys. Place the part of the candidate
key and the attribute it is functionally dependent on, in a different table.
Group the remaining attributes into a table
43
44
22
7/30/2024
45
45
46
23
7/30/2024
4NF Decomposition
Employee Skill Language
47
48
24
7/30/2024
49
50
25
7/30/2024
• Decompose Drinkers2
• Either MVD name ->-> phones or name ->-> beersLiked
tells us to decompose to:
• Drinkers3(name, phones)
• Drinkers4(name, beersLiked)
51
MVD Example
Drinkers(name, addr, phones, beersLiked)
• A drinker’s phones are independent of the beers they
like.
• namephones and namebeersLiked.
• Thus, each of a drinker’s phones appears with each of
the beers they like in all combinations.
52
26
7/30/2024
53
Example
Drinkers(name, addr, phones, beersLiked)
with MVD Name phones. If Drinkers has the
two tuples:
Name Addr Phone BeersLiked
Ram A P1 B1
Ram A P2 B2
Note: we must check this condition for all pairs of tuples that
agree on name, not just one pair.
54
27
7/30/2024
55
Denormalization in Databases
As the name suggests, denormalization is the opposite of normalization.
56
28