Dbms Normalization-Exercises Is304
Dbms Normalization-Exercises Is304
ITS 350
- Functional Dependency
Suppose R is a relation, X,Y are attributes over R, t1,t2 are tuples in the
relation R:
X Y
t1 a1 b1
t2 a2 b2
X→Y if and only if {(t1.X=t2.X)═►(t1.Y=t2.Y)}
A B
a1 b1
a2 b1
A→B is true (B is Functionally Dependent (FD) on A) because each value in A
achieves one atomic value in B.
A B
a1 b1
a1 b1
A→B is true (B is FD on A) because each value in A achieves one atomic value in
B.
A B
a1 b1
a1 b2
1
DBMS Normalization-Exercises IS304
ITS 350
A B
a1 b1
a2 b2
A→B is True (B is FD on A) because each value in A achieves different value in
B.
- Partial Dependency
Then, { A → C; A → D; A → E; B → C; B → D; B → E}
all are Partial Dependencies.
2
DBMS Normalization-Exercises ITS 350 IS304
Both (stud_id, course_name) are PK, and m_grade and f_grade depend on
this PK.
So m_grade and f_grade are partially depended on only course_name instead
on all PK componenets.
3
DBMS Normalization-Exercises ITS 350 IS304
{Book} → {Author}
{Author} does not → {Book}
{Author} → {Author Nationality}
Example-1: Suppose a company wants to store the names and contact details of its
employees. It creates a table that looks like this:
Three Employees (Sameer Hakim, Ali Hussain, and Hayat Fadhil ) have two
positions.The rule to make the relation in 1NF is (each tuple has single atomic
value), so we should separate the tuples which have more than one value in the
column.The result table is:
4
DBMS Normalization-Exercises IS304
ITS 350
5
DBMS Normalization-Exercises IS304
ITS 350
6
DBMS Normalization-Exercises IS304
ITS 350
2NF table is a relation that is in First Normal Form and every non-primary-key
attribute is fully functionally dependent on the primary key (not partial
dependency).
Exmaple-1: Suppose you have the following table:
The second rule is removing partial dependency and to do so you should divide the
table into sub-tables and ensure that the non-primary attributes depends on primary
attributes.
7
DBMS Normalization-Exercises IS304
ITS 350
8
DBMS Normalization-Exercises IS304
ITS 350
9
DBMS Normalization-Exercises IS304
ITS 350
The table in 1NF so we should start dividing the table to ensure the PK
dependency.
stud_name stud_birth
ali 1995
ahmed 1995
- Table in 2NF.
- No transitive dependency found.
10
DBMS Normalization-Exercises IS304
ITS 350
11
DBMS Normalization-Exercises IS304
ITS 350
12
DBMS Normalization-Exercises IS304
ITS 350
To convert them into 3NF we should ensure all non-primary key attributes
depend on PK attributes.
So:
Pet Names table:
pet_id pet pet_name name_id
1 Dog Rex 1
2 Cat Kitty 2
3 Cat Fluff 1
4 Dog Max 2
5 Cat Kimba 3
13
DBMS Normalization-Exercises IS304
ITS 350
14
DBMS Normalization-Exercises IS304
ITS 350
Q3: Examine the Patient Medication Form for the Wellmeadows Hospital case
study shown in figure.
(a) Identify the functional dependencies represented by the attributes shown in the
form in the figure.
State any assumptions you make about the data and the attributes shown in this
form.
15
DBMS Normalization-Exercises IS304
ITS 350
(b) Describe and illustrate the process of normalizing the attributes shown in the
figure to produce a set of well-designed 3NF relations.
(c) Identify the primary, alternate, and foreign keys in your 3NF relations.
Q4: convert the following tables into 3NF and give examples of (update, delete,
and insert anomalies):
1-
item colors price tax
T-Shirt red, blue 12$ 0.60
Trouser red, yellow 12$ 0.60
T-Shirt red, blue 12$ 0.60
Skirt black, blue 25$ 1.25
2-
name assignment1 assignment2
Ali Ahmed IS201 IS202
Sami Ali IS201 IS203
Ahmed Jabbar IS201 IS203
3-
course_id semester_id students_num course_name
IT101 201301 25 Database
IT101 201302 25 Database
IT102 201301 30 Web Design
IT102 201302 35 Web Design
IT103 201401 20 Networking
16