SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Downloaden Sie, um offline zu lesen
Functional Dependency
and
Normalization
7/24/2017 1Md. Golam Moazzam, Dept. of CSE, JU
7/24/2017 2Md. Golam Moazzam, Dept. of CSE, JU
OUTLINE
 Functional Dependency (FD)
 Inference Axioms for FDs
 Trivial and Non-trivial Dependency
 Canonical Cover
 Normalization Process: Objectives
 1NF, 2NF, 3NF
 Data Anomalies
 Partial Dependencies
 Transitive Dependencies
 Boyce-Codd Normal Form
 Decomposition: Lossless or Lossy
Functional Dependency
 Objectives
- To control the redundancy of data.
- To preserve the consistency of data.
Data redundancy occurs when a piece of data is stored in more
than one place in the database.
If the content of that piece of data is changed to a particular
value, then it is necessary to ensure that every copy of the same
piece of data is changed to the same value. This piece of data is
said to be consistent in the database.
If some, but not all, copies of this piece of data are changed to
the same value, the data is said to be inconsistent.
7/24/2017 3Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
 Functional Dependency (FD)
– Given a relation r(R) and two sets of its attributes A and B.
We will say that attribute(s) A functionally determines
attribute(s) B with respect to r, denoted by A → B, if and
only if for any two tuples t1 and t2 of r whenever
t1(A) = t2(A) then t1(B) =t2(B).
– That is, if A functionally determines B, then whenever two
tuples of r have identical values in column A, their
respective values in column B must also be identical.
7/24/2017 4Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
 Functional Dependency (FD)
7/24/2017 5Md. Golam Moazzam, Dept. of CSE, JU
Name Continent Area Length
Caspian Sea Asia – Europe 143244 760
Superior North America 31700 350
Victoria Africa 26828 250
Aral Sea Asia 24904 280
Huron North America 23000 206
Michigan North America 22300 307
Tanganyika Africa 12700 420
Lakes-of-The-World
Functional Dependency
 Functional Dependency (FD)
Example: Given the Lakes-Of-The-World relation shown
above, state whether or not the functional dependencies
(a) Continent → Name and
(b) Name → Length are satisfied by this relation.
7/24/2017 6Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
 Functional Dependency (FD)
(a) Here t1(Continent)= t2(Continent)=North America
But t1(Name)= Superior ≠ t2(Name)=Huron
So, Continent → Name is not satisfied by the relation
i.e. Continent Name.
(b) The functional dependency Name → Length is satisfied by
the relation. Because for any given lake, there is only one
length associated with it.
7/24/2017 7Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
 Inference Axioms for FDs/Armstrong's axioms
Given a set F of FDs, the inference axioms are a set of rules that tell
us that if a relation satisfies the FDs of F, the relation must satisfy
certain other FDs. The latter set of FDs are said to be derived or
logically deduced from the FDs of F.
1. If Y X, then X → Y (Reflexivity)
2. If X → Y, then XW → Y and/or XW → YW(Augmentation)
3. If X → Y and Y → Z, then X → Z (Transitivity)
4. If X → Y and YW → Z, then XW → Z (Pseudotransitivity)
5. If X → Z and X → Y, then X → YZ (Additivity or Union)
6. If X → YZ then X → Y and X → Z ( Projectivity or
Decomposition)
7/24/2017 8Md. Golam Moazzam, Dept. of CSE, JU

Functional Dependency
 Trivial and Non-trivial Dependency
Trivial
– A functional dependency FD: X → Y is called trivial if Y is a
subset of X.
– In other words, a dependency FD: X → Y means that the values
of Y are determined by the values of X.
Non-Trivial
– If an FD X → Y holds, where Y is not a subset of X, then it is
called a non-trivial FD.
7/24/2017 9Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
 Canonical Cover
For a given set F of FDs, a canonical cover, denoted by Fc, is a
set of FDs where the following conditions are simultaneously
satisfied:
1. Every FD of Fc is simple. That is, the right-hand side of
every functional dependency of Fc has only one attribute.
2. Fc is left-reduced.
3. Fc is nonredundant.
7/24/2017 10Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
 Canonical Cover
Example: Given the set F of FDs shown below, find a canonical cover for F.
F= {X → Z, XY → WP, XY → ZWQ, XZ → R}.
FC = {X → Z, XY → WP, XY → ZWQ, XZ → R}
= {X → Z, XY → W, XY → P, XY → Z, XY → W, XY → Q, XZ → R}. [Simple]
= {X → Z, XY → W, XY → P, XY → Z, XY → Q, XZ → R}. [Remove redundancy]
= {X → Z, XY → W, XY → P, XY → Z, XY → Q, XZ → R}.
= {X → Z, XY → W, XY → P, XY → Q, XZ → R}. [Remove redundancy]
= {X → Z, XY → W, XY → P, XY → Q, XZ → R}.
= {X → Z, XY → W, XY → P, XY → Q, X → R}. [Left-reduced]
FC = {X → Z, XY → W, XY → P, XY → Q, X → R}.
This resulting set where all FDs are simple, left-reduced and
non-redundant, is the canonical cover of F.
7/24/2017 11Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
Problem 1: Assume that AB → C, C → D and D → A are
simultaneously satisfied by a relation r(R). What are the
candidate keys of this relation? Which one is the PK? What are
the prime attributes? Are there any super keys for this relation?
Solution:
A set of attributes of r is a candidate key of r if and only if the
set functionally determines every attribute of the relation. The
set of attributes that can be selected as candidate keys of the
relation r are: AB and DB. Let's see why.
7/24/2017 12Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
Problem 1: Assume that AB → C, C → D and D → A . . . . .
AB is a candidate key.
The given FDs are: AB → C, C → D and D → A.
If AB is a key of r then it must be true that
AB → A, AB → B, AB→ C and AB→ D.
Using the inference axioms and the FDs of F we have that:
AB → A and AB → B ( Reflexivity axiom)
AB → C (given)
AB → C (given) and C → D (given) then AB → D (Transitivity
axiom)
Therefore, AB is a candidate key of the relation r because it
functionally determines any other attribute of the relation r.
7/24/2017 13Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
DB is another candidate key.
The given FDs are: AB → C, C → D and D → A.
If DB is a key of r then it must be true that
DB → A, DB → B, DB → C and DB → D.
Using the inference axioms and the FDs of we have that;
DB → D and DB → B (Reflexivity axiom)
DB → D (previous step) and D → A (given) we have that DB → A
(Transitivity axiom)
DB → A (from previous step) and AB → C (given) then DBB → C
(Pseudotransitivity axiom)
Since B U B= B we can rewrite DBB → C as DB → C.
Therefore, DB is a candidate key of the relation r because it
functionally determines all other attributes of the relation r.
7/24/2017 14Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
– There are two candidate keys AB and DB. However, only
one can be selected as the PK of the relation. The database
designer or the DBA should choose the one that makes more
sense or is more convenient for the application.
– The prime attributes of this relation are: A, B and D. A prime
attribute is any attribute that is part of a PK or an alternate
key.
– There are several super keys. They are: ABC, ADB, ABCD,
DBA, DBC and DBAC.
7/24/2017 15Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
Problem 2: Given the relation r(A, B, C) and the set F={AB → C, B →
D, D → B} of functional dependencies, find the candidate keys of the
relation. How many candidate keys are in this relation? What are the
prime attributes?
AB is a candidate key.
AB → A and AB → B ( Reflexivity axiom)
AB → C (given)
AB → B (step 1) and B → D (given) then AB → D ( Transitivity
axiom)
Since AB determines every other attribute of the relation, we have that
AB is a candidate key.
7/24/2017 16Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
Problem 2:. . . . .
AD is a candidate key.
AD → A and AD → D ( Reflexivity axiom)
AD → D (step 1) and D → B (given) then AD → B
AD → B (step 2) and AB → C (given) then AAD → C
(Pseudotransitivity axiom).
i.e. AD → C
Since AD determines every other attribute of the relation, we have that
AD is another candidate key.
The prime attributes are: A, B, and D.
7/24/2017 17Md. Golam Moazzam, Dept. of CSE, JU
Functional Dependency
 Prime and Non-prime attribute
– Prime attribute
• An attribute, which is a part of the primary-key, is known as a
prime attribute.
– Non-prime attribute
• An attribute, which is not a part of the primary-key, is said to
be a non-prime attribute.
7/24/2017 18Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Normalization
– It refers to a reversible step-by-step process in which a
given set of relations is replaced by successive collections
of relations that have a progressively simpler and more
regular structure.
– Each step is referred to as a normal form.
– Since the process is reversible, the original set of relations
can be recovered with no loss of information.
7/24/2017 19Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Objectives
– To make it feasible to represent any relation in the database.
– To obtain powerful relational retrieval algorithms based on a
collection of primitive relational operators.
– To free relations from undesirable insertion, update, and
deletion anomalies.
– To reduce the need for restructuring the relations as new data
types are introduced.
7/24/2017 20Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Question: Normalize step by step the following database into 1NF, 2NF
and 3NF:
PROJECT(Proj-ID, Proj-Name, Proj-Mgr-ID, Emp-ID, Emp-Name,
Emp-Dpt, Emp-Hrly-rate, Total-Hrs)
Solution:
Table entries that have more than one value are called multivalue
entries. Table with multivalue entries are called unnormalized tables.
Within an unnormalized table, we will call a repeating group an
attribute or group of attributes that may have multivalue entries for
single occurrences of the table identifier. Here table PROJECT is an
unnormalized table where attributes Emp-ID, Emp-Name, Emp-Dpt,
Emp-Hrly-rate, and Total-Hrs are repeating groups. Thus, we need to
put the table in first normal form (1NF).
7/24/2017 21Md. Golam Moazzam, Dept. of CSE, JU
Normalization
PROJECT(Proj-ID, Proj-Name, Proj-Mgr-ID, Emp-ID, Emp-Name,
Emp-Dpt, Emp-Hrly-rate, Total-Hrs)
FIRST NORMAL FORM (1NF)
– A relation r(R) is said to be in First Normal Form (1NF), if and
only if every entry of the relation has at most a single value.
– Thus, it requires to decompose the table PROJECT into two new
tables.
– It is also necessary to identify a PK for each table.
7/24/2017 22Md. Golam Moazzam, Dept. of CSE, JU
Normalization
PROJECT(Proj-ID, Proj-Name, Proj-Mgr-ID, Emp-ID, Emp-Name,
Emp-Dpt, Emp-Hrly-rate, Total-Hrs)
– First table with nonrepeating groups:
PROJECT (Proj-ID, Proj-Name, Proj-Mgr-ID)
– Second table with table identifier and all repeating groups:
PROJECT-EMPLOYEE (Proj-ID, Emp-ID, Emp-Name,
Emp-Dpt, Emp-Hrly-rate, Total-Hrs)
– Here Proj-ID is the table identifier.
7/24/2017 23Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Data Anomalies in 1NF Relations
– Redundancies in 1NF relations lead to a variety of data
anomalies:
• Insertion anomalies,
• Deletion anomalies and
• Update anomalies.
7/24/2017 24Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Data Anomalies in 1NF Relations
– Insertion anomalies occur in PROJECT-EMPLOYEE relation
because we cannot insert information about any new employee
unless that employee is already assigned to a project. Any attribute
of the composite key (Proj-ID, Emp-ID) cannot be NULL.
– Deletion anomalies occur when we delete the last tuple of a
particular employee. In this case, we not only delete the project
information that connects that employee to a particular project but
also lose other information about the department for which this
employee works.
7/24/2017 25Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Data Anomalies in 1NF Relations
– Update anomalies occur because the department for which an
employee works may appear many times in the table. It is this
redundancy of information that causes the anomaly because if
an employee moves to another department, we are now faced
with two problems: we either search the entire table looking
for that employee and update his Emp-Dpt value or we miss
one or more tuples of that employee and end up with an
inconsistent state.
7/24/2017 26Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Partial Dependencies
– Given a relation r(R), the sets of attributes X and Y ( X,Y R),
and X → Y, we will say that attribute Y is fully dependent on
attribute X if only if there is no proper subset W of X such
that W → Y.
– If there is a proper subset W of X such that W → Y then
attribute Y is said to be partially dependent on attribute X.
7/24/2017 27Md. Golam Moazzam, Dept. of CSE, JU

Normalization
Partial Dependencies
PROJECT-EMPLOYEE (Proj-ID, Emp-ID, Emp-Name, Emp-Dpt,
Emp-Hrly-rate, Total-Hrs)
7/24/2017 28Md. Golam Moazzam, Dept. of CSE, JU
Emp-Id
Proj-Id
Emp-Name
Emp-Dpt
Emp-Hrly-Rate
Normalization
SECOND NORMAL FORM (2NF)
A relation r (R) is in Second Normal Form (2NF) if and only if the
following two conditions are met simultaneously:
• r(R) is already in 1NF.
• No nonprime attribute is partially dependent on any key or,
equivalently, each nonprime attribute in R is fully dependent
on every key.
7/24/2017 29Md. Golam Moazzam, Dept. of CSE, JU
Normalization
SECOND NORMAL FORM (2NF)
– In PROJECT-EMPLOYEE relation attributes Emp-Name,
Emp-Dpt and Emp-Hrly-rate are fully dependent only on Emp-
ID.
– The only attribute Total-Hrs fully depends on the composite PK
(Proj-ID, Emp-ID). This is shown below.
7/24/2017 30Md. Golam Moazzam, Dept. of CSE, JU
PROJECT-EMPLOYEE (Proj-ID, Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, Total-Hrs)
Normalization
SECOND NORMAL FORM (2NF)
Now break this relation into two new relations so that partial dependency
does not exist.
– HOURS-ASSIGNED (Proj-ID, Emp-ID, Total-Hrs)
– EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate)
7/24/2017 31Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Data Anomalies in 2NF Relations
Relations in 2NF are still subject to data anomalies:
 Insertion anomalies,
 Deletion anomalies and
 Update anomalies.
7/24/2017 32Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Data Anomalies in 2NF Relations
Insertion anomalies:
– For sake of explanation, let us assume that the department in which
an employee works functionally determines the hourly rate charged
by that employee. That is,
Emp-Dpt → Emp-Hrly-rate.
– Insertion anomalies occur in the EMPLOYEE relation. For
example, consider a situation where we would like to set in
advance the rate to be charged by the employees for a new
department. We cannot insert this information until there is an
employee assigned to that department.
7/24/2017 33Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Data Anomalies in 2NF Relations
Deletion anomalies occur whenever we delete the tuple of an
employee who happens to be the only employee left in a department.
In this case, we lose the information about the rate that the department
charges.
Update anomalies occur because there may be several employees
from the same department working on different projects. If the
department rate changes, we need to make sure that the corresponding
rate is changed for all employees that work for that department.
Otherwise, the database may end up in an inconsistent state.
7/24/2017 34Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Transitive Dependencies
Assume that A, B, and C are the set of attributes of a relation r(R).
Further assume that the following functional dependencies are
satisfied simultaneously:
A → B,
B A,
B → C,
C A and A → C.
C → B is neither prohibited nor required.
If all these conditions are true, we will say that attribute C is
transitively dependent on attribute A.
7/24/2017 35Md. Golam Moazzam, Dept. of CSE, JU
Normalization
THIRD NORMAL FORM (3NF)
– A relation r(R) is in Third Normal Form (3NF) if and only if the
following conditions are satisfied simultaneously:
• r(R) is already in 2NF.
• No nonprime attribute is transitively dependent on the key (i.e.
No nonprime attribute functionally determines any other
nonprime attribute).
7/24/2017 36Md. Golam Moazzam, Dept. of CSE, JU
Normalization
THIRD NORMAL FORM (3NF)
In EMPLOYEE relation, attribute Emp-Hrly-rate is transitively
dependent on the PK Emp-ID through the functional dependency
Emp-Dpt → Emp-Hrly-rate. This is shown below.
7/24/2017 37Md. Golam Moazzam, Dept. of CSE, JU
EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate)
Normalization
THIRD NORMAL FORM (3NF)
7/24/2017 38Md. Golam Moazzam, Dept. of CSE, JU
EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate)
Now break this relation into two new relations so that transitive dependency does
not exist.
EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt)
CHARGES (Emp-Dpt, Emp-Hrly-rate)
The new set of relations that we have obtained through the normalization process
does not exhibit any of the anomalies. That is, we can insert, delete and update
tuples without any of the side effects.
Normalization
Data Anomalies in 3NF Relations
Relations in 3NF are still susceptible to data anomalies
particularly when the relations have two overlapping candidate
keys or when a non prime attribute functionally determines a
prime attribute.
7/24/2017 39Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Question. Normalize the following database step by step into 1NF,
2NF and 3NF:
SALES (Emp-No, Emp-Name, Store-Branch, Department, Item-No,
Item-Description, Sale-Price)
Solution:
Test Condition 1: Is the database unnormalized?
That is, repeating group and non-repeating group exist
simultaneously?
Then i) Decompose the table into two new tables.
ii) Identify PK for each table.
ii) Set a table identifier.
7/24/2017 40Md. Golam Moazzam, Dept. of CSE, JU
Normalization
SALES (Emp-No, Emp-Name, Store-Branch, Department, Item-No, Item-
Description, Sale-Price)
FIRST NORMAL FORM (1NF)
Non-Repeating group: Emp-No, Emp-Name, Store-Branch, Department
Repeating group: Item-No, Item-Description, Sale-Price
First table with non-repeating groups:
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
Second table with table identifier and all repeating groups:
SALES (Emp-No, Item-No, Item-Description, Sale-Price)
Here Emp-No is the table identifier.
7/24/2017 41Md. Golam Moazzam, Dept. of CSE, JU
Normalization
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
SALES (Emp-No, Item-No, Item-Description, Sale-Price)
SECOND NORMAL FORM (2NF)
Test Condition 2: Data anomalies occur? Partial dependency exists?
Then i) Decompose the table into two new tables.
ii) Identify PK for each table.
In SALES relation, attribute Sale-Price is fully dependent on the
composite PK (Emp-No, Item-No). The attribute Item-Description
depends only on Item-No. This is shown below.
7/24/2017 42Md. Golam Moazzam, Dept. of CSE, JU
SALES (Emp-No, Item-No, Item-Description, Sale-Price)
Normalization
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
SALES (Emp-No, Item-No, Item-Description, Sale-Price)
SECOND NORMAL FORM (2NF)
Now break the SALES relation into two new relations so that partial
dependency does not exist.
SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price)
ITEM-INFO (Item-No, Item-Description)
7/24/2017 43Md. Golam Moazzam, Dept. of CSE, JU
Normalization
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price)
ITEM-INFO (Item-No, Item-Description)
THIRD NORMAL FORM (3NF)
Test Condition 3: Data anomalies occur? Transitive dependency exists?
Then i) Decompose the table into two new tables.
ii) Identify PK for each table.
In SALESPERSON relation, attribute Department is transitively
dependent on the PK Emp-No. This is shown below.
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
7/24/2017 44Md. Golam Moazzam, Dept. of CSE, JU
Normalization
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price)
ITEM-INFO (Item-No, Item-Description)
THIRD NORMAL FORM (3NF)
7/24/2017 45Md. Golam Moazzam, Dept. of CSE, JU
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
Normalization
SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price)
ITEM-INFO (Item-No, Item-Description)
THIRD NORMAL FORM (3NF)
Now break the SALESPERSON relation into two new relations so that
transitive dependency does not exist.
SALESPERSON (Emp-No, Emp-Name, Store-Branch)
STORE (Store-Branch, Department)
7/24/2017 46Md. Golam Moazzam, Dept. of CSE, JU
Normalization
After 3NF, the new set of relations that we have obtained through the
normalization process does not exhibit any of the anomalies. That is,
we can insert, delete and update tuples without any of the side effects.
SALESPERSON (Emp-No, Emp-Name, Store-Branch)
STORE (Store-Branch, Department)
SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price)
ITEM-INFO (Item-No, Item-Description)
7/24/2017 47Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Data Anomalies in 3NF Relations
Example: Consider the MANUFACTURER relation shown below where
each manufacturer has a unique ID and name. Manufacturers produce
items (identified by their unique item numbers) in the amounts
indicated. Manufacturers may produce more than one item and
different Manufacturers may produce the same items.
MANUFACTURER
7/24/2017 48Md. Golam Moazzam, Dept. of CSE, JU
ID Name Item-No Quantity
M101 Electronics USA H3552 1000
M101 Electronics USA J08732 500
M101 Electronics USA Y23490 200
M322 Electronics-R-Us H3552 900
Normalization
Data Anomalies in 3NF Relations
– This MANUFACTURER relation has two candidate keys:
(ID, Item-No) and (Name, Item-No)
that overlap on the attribute Item-No.
– The relation is in 3NF because there is only one nonprime attribute
and therefore it is impossible that this attribute can determine
another nonprime attribute.
– The relation MANUFACTURER is susceptible to update
anomalies. Consider for example the case in which one of the
manufacturers changes its name. If the value of this attribute is not
changed in all of the corresponding tuples there is not possibility of
having an inconsistent database.
7/24/2017 49Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Boyce-Codd Normal Form
– A relation r(R) is in Boyce-Codd Normal Form (BCNF) if and only
of the following conditions are met simultaneously:
• The relation is in 3NF.
• For every functional dependency of the form X → A, we have
that either A X or X is a super key of r. In other words, every
functional dependency is either a trivial dependency or in the
case that the functional dependency is not trivial, then X must
be a super key.
7/24/2017 50Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Boyce-Codd Normal Form
– To transform the relation of example into BCNF, we can
decompose it onto the following set of relational schemes:
Set No. 1
– MANUFACTURER (ID, Name)
– MANUFACTURER-PART (ID, Item-No, Quantity)
OR, Set No. 2
– MANUFACTURER (ID, Name)
– MANUFACTURER-PART (Name, Item-No, Quantity)
7/24/2017 51Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Decomposition: Lossless or Lossy ?
– Whenever a relation is decomposed it is necessary to
ensure that the data in the original relation is represented
faithfully. That is, we need to make sure that we can
recover the original relation from the new relations that
have replaced it.
– Generally, the original relation is recovered by forming
the natural join of the new relations. If we can recover
the original relation we say that the decomposition is
lossless. Otherwise, it is lossy.
7/24/2017 52Md. Golam Moazzam, Dept. of CSE, JU
Normalization
Decomposition: Lossless or Lossy ?
Example: Consider the relation r shown below and its decomposition
R1 and R2. Is this decomposition lossless or lossy?
r R1 R2
7/24/2017 53Md. Golam Moazzam, Dept. of CSE, JU
X Y Z
x1 y1 z1
x2 y2 z2
x3 y2 z3
x4 y3 z4
X Y
x1 y1
x2 y2
x3 y2
x4 y3
Y Z
y1 z1
y2 z2
y2 z3
y3 z4
Decompose
Normalization
Lossless or Lossy Decomposition ?
r R1 R2
7/24/2017 54Md. Golam Moazzam, Dept. of CSE, JU
X Y Z
x1 y1 z1
x2 y2 z2
x3 y2 z3
x4 y3 z4
X Y
x1 y1
x2 y2
x3 y2
x4 y3
Y Z
y1 z1
y2 z2
y2 z3
y3 z4
Decompose
X Y Z
x1 y1 z1
x2 y2 z2
x2 y2 z3
x3 y2 z2
x3 y2 z3
x4 y3 z4
R1 Join R2
Normalization
Lossless or Lossy Decomposition ?
Example: Consider the relation r shown below and its decomposition
R1 and R2. Is this decomposition lossless or lossy?
Notice that the natural join of R1 and R2 has tuples that were not
present in the original relation. These tuples are called spurious tuples
because they represent spurious or false information. Since the
natural join of R1 and R2 does not recover the original relation, the
decomposition is lossy.
7/24/2017 55Md. Golam Moazzam, Dept. of CSE, JU

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

File organization 1
File organization 1File organization 1
File organization 1
 
Dbms3
Dbms3Dbms3
Dbms3
 
Query processing in Distributed Database System
Query processing in Distributed Database SystemQuery processing in Distributed Database System
Query processing in Distributed Database System
 
Data base management system
Data base management systemData base management system
Data base management system
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
joins in database
 joins in database joins in database
joins in database
 
Normalization
NormalizationNormalization
Normalization
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
11 Database Concepts
11 Database Concepts11 Database Concepts
11 Database Concepts
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Relational model
Relational modelRelational model
Relational model
 
Fd & Normalization - Database Management System
Fd & Normalization - Database Management SystemFd & Normalization - Database Management System
Fd & Normalization - Database Management System
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Serializability
SerializabilitySerializability
Serializability
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Dbms normalization
Dbms normalizationDbms normalization
Dbms normalization
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 

Ähnlich wie Functional dependency and normalization

Ähnlich wie Functional dependency and normalization (20)

Normalization
NormalizationNormalization
Normalization
 
Dbms unit-3
Dbms unit-3Dbms unit-3
Dbms unit-3
 
MODULE 4 -Normalization_1.ppt
MODULE 4 -Normalization_1.pptMODULE 4 -Normalization_1.ppt
MODULE 4 -Normalization_1.ppt
 
Normalization
NormalizationNormalization
Normalization
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
Normalization
NormalizationNormalization
Normalization
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
DBMS unit-3.pdf
DBMS unit-3.pdfDBMS unit-3.pdf
DBMS unit-3.pdf
 
Database Management System [DBMS]
Database Management System [DBMS]Database Management System [DBMS]
Database Management System [DBMS]
 
Introduction to database-Normalisation
Introduction to database-NormalisationIntroduction to database-Normalisation
Introduction to database-Normalisation
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
Chapter-8 Relational Database Design
Chapter-8 Relational Database DesignChapter-8 Relational Database Design
Chapter-8 Relational Database Design
 
DBMS-Normalization.ppt
DBMS-Normalization.pptDBMS-Normalization.ppt
DBMS-Normalization.ppt
 
functional dependency in engineering.pptx
functional dependency in engineering.pptxfunctional dependency in engineering.pptx
functional dependency in engineering.pptx
 
DBMS Unit 3.pptx
DBMS Unit 3.pptxDBMS Unit 3.pptx
DBMS Unit 3.pptx
 
Normalization in Database
Normalization in DatabaseNormalization in Database
Normalization in Database
 
ALGORITHM FOR RELATIONAL DATABASE NORMALIZATION UP TO 3NF
ALGORITHM FOR RELATIONAL DATABASE NORMALIZATION UP TO 3NFALGORITHM FOR RELATIONAL DATABASE NORMALIZATION UP TO 3NF
ALGORITHM FOR RELATIONAL DATABASE NORMALIZATION UP TO 3NF
 
Theory of dependencies in relational database
Theory of dependencies in relational databaseTheory of dependencies in relational database
Theory of dependencies in relational database
 
Normalization
NormalizationNormalization
Normalization
 
Cs501 fd nf
Cs501 fd nfCs501 fd nf
Cs501 fd nf
 

Mehr von University of Potsdam (20)

Computer fundamentals 01
Computer fundamentals 01Computer fundamentals 01
Computer fundamentals 01
 
Workshop on android apps development
Workshop on android apps developmentWorkshop on android apps development
Workshop on android apps development
 
Transparency and concurrency
Transparency and concurrencyTransparency and concurrency
Transparency and concurrency
 
Database System Architecture
Database System ArchitectureDatabase System Architecture
Database System Architecture
 
indexing and hashing
indexing and hashingindexing and hashing
indexing and hashing
 
data recovery-raid
data recovery-raiddata recovery-raid
data recovery-raid
 
Query processing
Query processingQuery processing
Query processing
 
Machine Learning for Data Mining
Machine Learning for Data MiningMachine Learning for Data Mining
Machine Learning for Data Mining
 
Tree, function and graph
Tree, function and graphTree, function and graph
Tree, function and graph
 
Sonet
SonetSonet
Sonet
 
Sets in discrete mathematics
Sets in discrete mathematicsSets in discrete mathematics
Sets in discrete mathematics
 
Set in discrete mathematics
Set in discrete mathematicsSet in discrete mathematics
Set in discrete mathematics
 
Series parallel ac rlc networks
Series parallel ac rlc networksSeries parallel ac rlc networks
Series parallel ac rlc networks
 
Series parallel ac networks
Series parallel ac networksSeries parallel ac networks
Series parallel ac networks
 
Relations
RelationsRelations
Relations
 
Relations
RelationsRelations
Relations
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
 
Predicate & quantifier
Predicate & quantifierPredicate & quantifier
Predicate & quantifier
 

Kürzlich hochgeladen

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Kürzlich hochgeladen (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

Functional dependency and normalization

  • 2. 7/24/2017 2Md. Golam Moazzam, Dept. of CSE, JU OUTLINE  Functional Dependency (FD)  Inference Axioms for FDs  Trivial and Non-trivial Dependency  Canonical Cover  Normalization Process: Objectives  1NF, 2NF, 3NF  Data Anomalies  Partial Dependencies  Transitive Dependencies  Boyce-Codd Normal Form  Decomposition: Lossless or Lossy
  • 3. Functional Dependency  Objectives - To control the redundancy of data. - To preserve the consistency of data. Data redundancy occurs when a piece of data is stored in more than one place in the database. If the content of that piece of data is changed to a particular value, then it is necessary to ensure that every copy of the same piece of data is changed to the same value. This piece of data is said to be consistent in the database. If some, but not all, copies of this piece of data are changed to the same value, the data is said to be inconsistent. 7/24/2017 3Md. Golam Moazzam, Dept. of CSE, JU
  • 4. Functional Dependency  Functional Dependency (FD) – Given a relation r(R) and two sets of its attributes A and B. We will say that attribute(s) A functionally determines attribute(s) B with respect to r, denoted by A → B, if and only if for any two tuples t1 and t2 of r whenever t1(A) = t2(A) then t1(B) =t2(B). – That is, if A functionally determines B, then whenever two tuples of r have identical values in column A, their respective values in column B must also be identical. 7/24/2017 4Md. Golam Moazzam, Dept. of CSE, JU
  • 5. Functional Dependency  Functional Dependency (FD) 7/24/2017 5Md. Golam Moazzam, Dept. of CSE, JU Name Continent Area Length Caspian Sea Asia – Europe 143244 760 Superior North America 31700 350 Victoria Africa 26828 250 Aral Sea Asia 24904 280 Huron North America 23000 206 Michigan North America 22300 307 Tanganyika Africa 12700 420 Lakes-of-The-World
  • 6. Functional Dependency  Functional Dependency (FD) Example: Given the Lakes-Of-The-World relation shown above, state whether or not the functional dependencies (a) Continent → Name and (b) Name → Length are satisfied by this relation. 7/24/2017 6Md. Golam Moazzam, Dept. of CSE, JU
  • 7. Functional Dependency  Functional Dependency (FD) (a) Here t1(Continent)= t2(Continent)=North America But t1(Name)= Superior ≠ t2(Name)=Huron So, Continent → Name is not satisfied by the relation i.e. Continent Name. (b) The functional dependency Name → Length is satisfied by the relation. Because for any given lake, there is only one length associated with it. 7/24/2017 7Md. Golam Moazzam, Dept. of CSE, JU
  • 8. Functional Dependency  Inference Axioms for FDs/Armstrong's axioms Given a set F of FDs, the inference axioms are a set of rules that tell us that if a relation satisfies the FDs of F, the relation must satisfy certain other FDs. The latter set of FDs are said to be derived or logically deduced from the FDs of F. 1. If Y X, then X → Y (Reflexivity) 2. If X → Y, then XW → Y and/or XW → YW(Augmentation) 3. If X → Y and Y → Z, then X → Z (Transitivity) 4. If X → Y and YW → Z, then XW → Z (Pseudotransitivity) 5. If X → Z and X → Y, then X → YZ (Additivity or Union) 6. If X → YZ then X → Y and X → Z ( Projectivity or Decomposition) 7/24/2017 8Md. Golam Moazzam, Dept. of CSE, JU 
  • 9. Functional Dependency  Trivial and Non-trivial Dependency Trivial – A functional dependency FD: X → Y is called trivial if Y is a subset of X. – In other words, a dependency FD: X → Y means that the values of Y are determined by the values of X. Non-Trivial – If an FD X → Y holds, where Y is not a subset of X, then it is called a non-trivial FD. 7/24/2017 9Md. Golam Moazzam, Dept. of CSE, JU
  • 10. Functional Dependency  Canonical Cover For a given set F of FDs, a canonical cover, denoted by Fc, is a set of FDs where the following conditions are simultaneously satisfied: 1. Every FD of Fc is simple. That is, the right-hand side of every functional dependency of Fc has only one attribute. 2. Fc is left-reduced. 3. Fc is nonredundant. 7/24/2017 10Md. Golam Moazzam, Dept. of CSE, JU
  • 11. Functional Dependency  Canonical Cover Example: Given the set F of FDs shown below, find a canonical cover for F. F= {X → Z, XY → WP, XY → ZWQ, XZ → R}. FC = {X → Z, XY → WP, XY → ZWQ, XZ → R} = {X → Z, XY → W, XY → P, XY → Z, XY → W, XY → Q, XZ → R}. [Simple] = {X → Z, XY → W, XY → P, XY → Z, XY → Q, XZ → R}. [Remove redundancy] = {X → Z, XY → W, XY → P, XY → Z, XY → Q, XZ → R}. = {X → Z, XY → W, XY → P, XY → Q, XZ → R}. [Remove redundancy] = {X → Z, XY → W, XY → P, XY → Q, XZ → R}. = {X → Z, XY → W, XY → P, XY → Q, X → R}. [Left-reduced] FC = {X → Z, XY → W, XY → P, XY → Q, X → R}. This resulting set where all FDs are simple, left-reduced and non-redundant, is the canonical cover of F. 7/24/2017 11Md. Golam Moazzam, Dept. of CSE, JU
  • 12. Functional Dependency Problem 1: Assume that AB → C, C → D and D → A are simultaneously satisfied by a relation r(R). What are the candidate keys of this relation? Which one is the PK? What are the prime attributes? Are there any super keys for this relation? Solution: A set of attributes of r is a candidate key of r if and only if the set functionally determines every attribute of the relation. The set of attributes that can be selected as candidate keys of the relation r are: AB and DB. Let's see why. 7/24/2017 12Md. Golam Moazzam, Dept. of CSE, JU
  • 13. Functional Dependency Problem 1: Assume that AB → C, C → D and D → A . . . . . AB is a candidate key. The given FDs are: AB → C, C → D and D → A. If AB is a key of r then it must be true that AB → A, AB → B, AB→ C and AB→ D. Using the inference axioms and the FDs of F we have that: AB → A and AB → B ( Reflexivity axiom) AB → C (given) AB → C (given) and C → D (given) then AB → D (Transitivity axiom) Therefore, AB is a candidate key of the relation r because it functionally determines any other attribute of the relation r. 7/24/2017 13Md. Golam Moazzam, Dept. of CSE, JU
  • 14. Functional Dependency DB is another candidate key. The given FDs are: AB → C, C → D and D → A. If DB is a key of r then it must be true that DB → A, DB → B, DB → C and DB → D. Using the inference axioms and the FDs of we have that; DB → D and DB → B (Reflexivity axiom) DB → D (previous step) and D → A (given) we have that DB → A (Transitivity axiom) DB → A (from previous step) and AB → C (given) then DBB → C (Pseudotransitivity axiom) Since B U B= B we can rewrite DBB → C as DB → C. Therefore, DB is a candidate key of the relation r because it functionally determines all other attributes of the relation r. 7/24/2017 14Md. Golam Moazzam, Dept. of CSE, JU
  • 15. Functional Dependency – There are two candidate keys AB and DB. However, only one can be selected as the PK of the relation. The database designer or the DBA should choose the one that makes more sense or is more convenient for the application. – The prime attributes of this relation are: A, B and D. A prime attribute is any attribute that is part of a PK or an alternate key. – There are several super keys. They are: ABC, ADB, ABCD, DBA, DBC and DBAC. 7/24/2017 15Md. Golam Moazzam, Dept. of CSE, JU
  • 16. Functional Dependency Problem 2: Given the relation r(A, B, C) and the set F={AB → C, B → D, D → B} of functional dependencies, find the candidate keys of the relation. How many candidate keys are in this relation? What are the prime attributes? AB is a candidate key. AB → A and AB → B ( Reflexivity axiom) AB → C (given) AB → B (step 1) and B → D (given) then AB → D ( Transitivity axiom) Since AB determines every other attribute of the relation, we have that AB is a candidate key. 7/24/2017 16Md. Golam Moazzam, Dept. of CSE, JU
  • 17. Functional Dependency Problem 2:. . . . . AD is a candidate key. AD → A and AD → D ( Reflexivity axiom) AD → D (step 1) and D → B (given) then AD → B AD → B (step 2) and AB → C (given) then AAD → C (Pseudotransitivity axiom). i.e. AD → C Since AD determines every other attribute of the relation, we have that AD is another candidate key. The prime attributes are: A, B, and D. 7/24/2017 17Md. Golam Moazzam, Dept. of CSE, JU
  • 18. Functional Dependency  Prime and Non-prime attribute – Prime attribute • An attribute, which is a part of the primary-key, is known as a prime attribute. – Non-prime attribute • An attribute, which is not a part of the primary-key, is said to be a non-prime attribute. 7/24/2017 18Md. Golam Moazzam, Dept. of CSE, JU
  • 19. Normalization Normalization – It refers to a reversible step-by-step process in which a given set of relations is replaced by successive collections of relations that have a progressively simpler and more regular structure. – Each step is referred to as a normal form. – Since the process is reversible, the original set of relations can be recovered with no loss of information. 7/24/2017 19Md. Golam Moazzam, Dept. of CSE, JU
  • 20. Normalization Objectives – To make it feasible to represent any relation in the database. – To obtain powerful relational retrieval algorithms based on a collection of primitive relational operators. – To free relations from undesirable insertion, update, and deletion anomalies. – To reduce the need for restructuring the relations as new data types are introduced. 7/24/2017 20Md. Golam Moazzam, Dept. of CSE, JU
  • 21. Normalization Question: Normalize step by step the following database into 1NF, 2NF and 3NF: PROJECT(Proj-ID, Proj-Name, Proj-Mgr-ID, Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, Total-Hrs) Solution: Table entries that have more than one value are called multivalue entries. Table with multivalue entries are called unnormalized tables. Within an unnormalized table, we will call a repeating group an attribute or group of attributes that may have multivalue entries for single occurrences of the table identifier. Here table PROJECT is an unnormalized table where attributes Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, and Total-Hrs are repeating groups. Thus, we need to put the table in first normal form (1NF). 7/24/2017 21Md. Golam Moazzam, Dept. of CSE, JU
  • 22. Normalization PROJECT(Proj-ID, Proj-Name, Proj-Mgr-ID, Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, Total-Hrs) FIRST NORMAL FORM (1NF) – A relation r(R) is said to be in First Normal Form (1NF), if and only if every entry of the relation has at most a single value. – Thus, it requires to decompose the table PROJECT into two new tables. – It is also necessary to identify a PK for each table. 7/24/2017 22Md. Golam Moazzam, Dept. of CSE, JU
  • 23. Normalization PROJECT(Proj-ID, Proj-Name, Proj-Mgr-ID, Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, Total-Hrs) – First table with nonrepeating groups: PROJECT (Proj-ID, Proj-Name, Proj-Mgr-ID) – Second table with table identifier and all repeating groups: PROJECT-EMPLOYEE (Proj-ID, Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, Total-Hrs) – Here Proj-ID is the table identifier. 7/24/2017 23Md. Golam Moazzam, Dept. of CSE, JU
  • 24. Normalization Data Anomalies in 1NF Relations – Redundancies in 1NF relations lead to a variety of data anomalies: • Insertion anomalies, • Deletion anomalies and • Update anomalies. 7/24/2017 24Md. Golam Moazzam, Dept. of CSE, JU
  • 25. Normalization Data Anomalies in 1NF Relations – Insertion anomalies occur in PROJECT-EMPLOYEE relation because we cannot insert information about any new employee unless that employee is already assigned to a project. Any attribute of the composite key (Proj-ID, Emp-ID) cannot be NULL. – Deletion anomalies occur when we delete the last tuple of a particular employee. In this case, we not only delete the project information that connects that employee to a particular project but also lose other information about the department for which this employee works. 7/24/2017 25Md. Golam Moazzam, Dept. of CSE, JU
  • 26. Normalization Data Anomalies in 1NF Relations – Update anomalies occur because the department for which an employee works may appear many times in the table. It is this redundancy of information that causes the anomaly because if an employee moves to another department, we are now faced with two problems: we either search the entire table looking for that employee and update his Emp-Dpt value or we miss one or more tuples of that employee and end up with an inconsistent state. 7/24/2017 26Md. Golam Moazzam, Dept. of CSE, JU
  • 27. Normalization Partial Dependencies – Given a relation r(R), the sets of attributes X and Y ( X,Y R), and X → Y, we will say that attribute Y is fully dependent on attribute X if only if there is no proper subset W of X such that W → Y. – If there is a proper subset W of X such that W → Y then attribute Y is said to be partially dependent on attribute X. 7/24/2017 27Md. Golam Moazzam, Dept. of CSE, JU 
  • 28. Normalization Partial Dependencies PROJECT-EMPLOYEE (Proj-ID, Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, Total-Hrs) 7/24/2017 28Md. Golam Moazzam, Dept. of CSE, JU Emp-Id Proj-Id Emp-Name Emp-Dpt Emp-Hrly-Rate
  • 29. Normalization SECOND NORMAL FORM (2NF) A relation r (R) is in Second Normal Form (2NF) if and only if the following two conditions are met simultaneously: • r(R) is already in 1NF. • No nonprime attribute is partially dependent on any key or, equivalently, each nonprime attribute in R is fully dependent on every key. 7/24/2017 29Md. Golam Moazzam, Dept. of CSE, JU
  • 30. Normalization SECOND NORMAL FORM (2NF) – In PROJECT-EMPLOYEE relation attributes Emp-Name, Emp-Dpt and Emp-Hrly-rate are fully dependent only on Emp- ID. – The only attribute Total-Hrs fully depends on the composite PK (Proj-ID, Emp-ID). This is shown below. 7/24/2017 30Md. Golam Moazzam, Dept. of CSE, JU PROJECT-EMPLOYEE (Proj-ID, Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate, Total-Hrs)
  • 31. Normalization SECOND NORMAL FORM (2NF) Now break this relation into two new relations so that partial dependency does not exist. – HOURS-ASSIGNED (Proj-ID, Emp-ID, Total-Hrs) – EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate) 7/24/2017 31Md. Golam Moazzam, Dept. of CSE, JU
  • 32. Normalization Data Anomalies in 2NF Relations Relations in 2NF are still subject to data anomalies:  Insertion anomalies,  Deletion anomalies and  Update anomalies. 7/24/2017 32Md. Golam Moazzam, Dept. of CSE, JU
  • 33. Normalization Data Anomalies in 2NF Relations Insertion anomalies: – For sake of explanation, let us assume that the department in which an employee works functionally determines the hourly rate charged by that employee. That is, Emp-Dpt → Emp-Hrly-rate. – Insertion anomalies occur in the EMPLOYEE relation. For example, consider a situation where we would like to set in advance the rate to be charged by the employees for a new department. We cannot insert this information until there is an employee assigned to that department. 7/24/2017 33Md. Golam Moazzam, Dept. of CSE, JU
  • 34. Normalization Data Anomalies in 2NF Relations Deletion anomalies occur whenever we delete the tuple of an employee who happens to be the only employee left in a department. In this case, we lose the information about the rate that the department charges. Update anomalies occur because there may be several employees from the same department working on different projects. If the department rate changes, we need to make sure that the corresponding rate is changed for all employees that work for that department. Otherwise, the database may end up in an inconsistent state. 7/24/2017 34Md. Golam Moazzam, Dept. of CSE, JU
  • 35. Normalization Transitive Dependencies Assume that A, B, and C are the set of attributes of a relation r(R). Further assume that the following functional dependencies are satisfied simultaneously: A → B, B A, B → C, C A and A → C. C → B is neither prohibited nor required. If all these conditions are true, we will say that attribute C is transitively dependent on attribute A. 7/24/2017 35Md. Golam Moazzam, Dept. of CSE, JU
  • 36. Normalization THIRD NORMAL FORM (3NF) – A relation r(R) is in Third Normal Form (3NF) if and only if the following conditions are satisfied simultaneously: • r(R) is already in 2NF. • No nonprime attribute is transitively dependent on the key (i.e. No nonprime attribute functionally determines any other nonprime attribute). 7/24/2017 36Md. Golam Moazzam, Dept. of CSE, JU
  • 37. Normalization THIRD NORMAL FORM (3NF) In EMPLOYEE relation, attribute Emp-Hrly-rate is transitively dependent on the PK Emp-ID through the functional dependency Emp-Dpt → Emp-Hrly-rate. This is shown below. 7/24/2017 37Md. Golam Moazzam, Dept. of CSE, JU EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate)
  • 38. Normalization THIRD NORMAL FORM (3NF) 7/24/2017 38Md. Golam Moazzam, Dept. of CSE, JU EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt, Emp-Hrly-rate) Now break this relation into two new relations so that transitive dependency does not exist. EMPLOYEE (Emp-ID, Emp-Name, Emp-Dpt) CHARGES (Emp-Dpt, Emp-Hrly-rate) The new set of relations that we have obtained through the normalization process does not exhibit any of the anomalies. That is, we can insert, delete and update tuples without any of the side effects.
  • 39. Normalization Data Anomalies in 3NF Relations Relations in 3NF are still susceptible to data anomalies particularly when the relations have two overlapping candidate keys or when a non prime attribute functionally determines a prime attribute. 7/24/2017 39Md. Golam Moazzam, Dept. of CSE, JU
  • 40. Normalization Question. Normalize the following database step by step into 1NF, 2NF and 3NF: SALES (Emp-No, Emp-Name, Store-Branch, Department, Item-No, Item-Description, Sale-Price) Solution: Test Condition 1: Is the database unnormalized? That is, repeating group and non-repeating group exist simultaneously? Then i) Decompose the table into two new tables. ii) Identify PK for each table. ii) Set a table identifier. 7/24/2017 40Md. Golam Moazzam, Dept. of CSE, JU
  • 41. Normalization SALES (Emp-No, Emp-Name, Store-Branch, Department, Item-No, Item- Description, Sale-Price) FIRST NORMAL FORM (1NF) Non-Repeating group: Emp-No, Emp-Name, Store-Branch, Department Repeating group: Item-No, Item-Description, Sale-Price First table with non-repeating groups: SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department) Second table with table identifier and all repeating groups: SALES (Emp-No, Item-No, Item-Description, Sale-Price) Here Emp-No is the table identifier. 7/24/2017 41Md. Golam Moazzam, Dept. of CSE, JU
  • 42. Normalization SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department) SALES (Emp-No, Item-No, Item-Description, Sale-Price) SECOND NORMAL FORM (2NF) Test Condition 2: Data anomalies occur? Partial dependency exists? Then i) Decompose the table into two new tables. ii) Identify PK for each table. In SALES relation, attribute Sale-Price is fully dependent on the composite PK (Emp-No, Item-No). The attribute Item-Description depends only on Item-No. This is shown below. 7/24/2017 42Md. Golam Moazzam, Dept. of CSE, JU SALES (Emp-No, Item-No, Item-Description, Sale-Price)
  • 43. Normalization SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department) SALES (Emp-No, Item-No, Item-Description, Sale-Price) SECOND NORMAL FORM (2NF) Now break the SALES relation into two new relations so that partial dependency does not exist. SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price) ITEM-INFO (Item-No, Item-Description) 7/24/2017 43Md. Golam Moazzam, Dept. of CSE, JU
  • 44. Normalization SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department) SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price) ITEM-INFO (Item-No, Item-Description) THIRD NORMAL FORM (3NF) Test Condition 3: Data anomalies occur? Transitive dependency exists? Then i) Decompose the table into two new tables. ii) Identify PK for each table. In SALESPERSON relation, attribute Department is transitively dependent on the PK Emp-No. This is shown below. SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department) 7/24/2017 44Md. Golam Moazzam, Dept. of CSE, JU
  • 45. Normalization SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department) SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price) ITEM-INFO (Item-No, Item-Description) THIRD NORMAL FORM (3NF) 7/24/2017 45Md. Golam Moazzam, Dept. of CSE, JU SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department)
  • 46. Normalization SALESPERSON (Emp-No, Emp-Name, Store-Branch, Department) SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price) ITEM-INFO (Item-No, Item-Description) THIRD NORMAL FORM (3NF) Now break the SALESPERSON relation into two new relations so that transitive dependency does not exist. SALESPERSON (Emp-No, Emp-Name, Store-Branch) STORE (Store-Branch, Department) 7/24/2017 46Md. Golam Moazzam, Dept. of CSE, JU
  • 47. Normalization After 3NF, the new set of relations that we have obtained through the normalization process does not exhibit any of the anomalies. That is, we can insert, delete and update tuples without any of the side effects. SALESPERSON (Emp-No, Emp-Name, Store-Branch) STORE (Store-Branch, Department) SALESPERSON-ITEM (Emp-No, Item-No, Sale-Price) ITEM-INFO (Item-No, Item-Description) 7/24/2017 47Md. Golam Moazzam, Dept. of CSE, JU
  • 48. Normalization Data Anomalies in 3NF Relations Example: Consider the MANUFACTURER relation shown below where each manufacturer has a unique ID and name. Manufacturers produce items (identified by their unique item numbers) in the amounts indicated. Manufacturers may produce more than one item and different Manufacturers may produce the same items. MANUFACTURER 7/24/2017 48Md. Golam Moazzam, Dept. of CSE, JU ID Name Item-No Quantity M101 Electronics USA H3552 1000 M101 Electronics USA J08732 500 M101 Electronics USA Y23490 200 M322 Electronics-R-Us H3552 900
  • 49. Normalization Data Anomalies in 3NF Relations – This MANUFACTURER relation has two candidate keys: (ID, Item-No) and (Name, Item-No) that overlap on the attribute Item-No. – The relation is in 3NF because there is only one nonprime attribute and therefore it is impossible that this attribute can determine another nonprime attribute. – The relation MANUFACTURER is susceptible to update anomalies. Consider for example the case in which one of the manufacturers changes its name. If the value of this attribute is not changed in all of the corresponding tuples there is not possibility of having an inconsistent database. 7/24/2017 49Md. Golam Moazzam, Dept. of CSE, JU
  • 50. Normalization Boyce-Codd Normal Form – A relation r(R) is in Boyce-Codd Normal Form (BCNF) if and only of the following conditions are met simultaneously: • The relation is in 3NF. • For every functional dependency of the form X → A, we have that either A X or X is a super key of r. In other words, every functional dependency is either a trivial dependency or in the case that the functional dependency is not trivial, then X must be a super key. 7/24/2017 50Md. Golam Moazzam, Dept. of CSE, JU
  • 51. Normalization Boyce-Codd Normal Form – To transform the relation of example into BCNF, we can decompose it onto the following set of relational schemes: Set No. 1 – MANUFACTURER (ID, Name) – MANUFACTURER-PART (ID, Item-No, Quantity) OR, Set No. 2 – MANUFACTURER (ID, Name) – MANUFACTURER-PART (Name, Item-No, Quantity) 7/24/2017 51Md. Golam Moazzam, Dept. of CSE, JU
  • 52. Normalization Decomposition: Lossless or Lossy ? – Whenever a relation is decomposed it is necessary to ensure that the data in the original relation is represented faithfully. That is, we need to make sure that we can recover the original relation from the new relations that have replaced it. – Generally, the original relation is recovered by forming the natural join of the new relations. If we can recover the original relation we say that the decomposition is lossless. Otherwise, it is lossy. 7/24/2017 52Md. Golam Moazzam, Dept. of CSE, JU
  • 53. Normalization Decomposition: Lossless or Lossy ? Example: Consider the relation r shown below and its decomposition R1 and R2. Is this decomposition lossless or lossy? r R1 R2 7/24/2017 53Md. Golam Moazzam, Dept. of CSE, JU X Y Z x1 y1 z1 x2 y2 z2 x3 y2 z3 x4 y3 z4 X Y x1 y1 x2 y2 x3 y2 x4 y3 Y Z y1 z1 y2 z2 y2 z3 y3 z4 Decompose
  • 54. Normalization Lossless or Lossy Decomposition ? r R1 R2 7/24/2017 54Md. Golam Moazzam, Dept. of CSE, JU X Y Z x1 y1 z1 x2 y2 z2 x3 y2 z3 x4 y3 z4 X Y x1 y1 x2 y2 x3 y2 x4 y3 Y Z y1 z1 y2 z2 y2 z3 y3 z4 Decompose X Y Z x1 y1 z1 x2 y2 z2 x2 y2 z3 x3 y2 z2 x3 y2 z3 x4 y3 z4 R1 Join R2
  • 55. Normalization Lossless or Lossy Decomposition ? Example: Consider the relation r shown below and its decomposition R1 and R2. Is this decomposition lossless or lossy? Notice that the natural join of R1 and R2 has tuples that were not present in the original relation. These tuples are called spurious tuples because they represent spurious or false information. Since the natural join of R1 and R2 does not recover the original relation, the decomposition is lossy. 7/24/2017 55Md. Golam Moazzam, Dept. of CSE, JU