Post on 09-Apr-2018
8/8/2019 Ab Normalization Upload
1/26
Functional Dependency
8/8/2019 Ab Normalization Upload
2/26
What it is?
An attribute or set of attributes X is said tofunctionally determine another attribute
Y (written X Y) if and only if each X value is
associated with at most one Y value.
Customarily we call X determinant set andY a dependent set.
A functional dependency is a constraint between
two sets of attributes in a relation from a database.
So if we are given the value of X we can determine
the value of Y.
8/8/2019 Ab Normalization Upload
3/26
The determination of functional dependencies
is an important part of designing databases inthe relational model, and in database normalization
and denormalization.
Why is Fanctional Dependency
Important?
The functional dependencies, along with the attribute
domains, are selected so as to generate constraintsthat would exclude as much data inappropriate to
the user domain from the system as possible.
8/8/2019 Ab Normalization Upload
4/26
Functional Dependency
Inference Rules
Reflexivity:
If B is a subset of A then A functionally determines B
For example:
{name, location} {name}
8/8/2019 Ab Normalization Upload
5/26
Functional Dependency
Inference Rules(cont.)
Augmentation:
If B is a subset of A and C functionally determines D
then A and C functionally determine B and D
For example:{name, location} and {birthdate, time} {name} and {age}
(as {name} is a subset of{name, location} and {birthdate, time}
functionally determines {age})
8/8/2019 Ab Normalization Upload
6/26
Functional Dependency
Inference Rules(cont.)
Transitivity:
If A functionally determines B and B functionally
determines C then A functionally determines C
For example:{name, location} {initials}
(as {name, location} functionally determines
{name} and {name} functionally determines {initials})
8/8/2019 Ab Normalization Upload
7/26
Functional Dependency
Inference Rules(cont.)
Pseudo transitivity:
If A functionally determines B and
B and C functionally determine D
then A and C functionally determine D
8/8/2019 Ab Normalization Upload
8/26
Functional Dependency
Inference Rules(cont.)
Union:
If A functionally determines B and A functionally
determines C then A functionally determines B and C
For example:{name, location, birthdate, time} {initials, age}
(as {name, location, birthdate, time} {initials} and
{name, location, birthdate, time} {age})
8/8/2019 Ab Normalization Upload
9/26
Functional Dependency
Inference Rules(cont.)Decomposition:
If A functionally determines B and Cthen A functionally determines B and
A functionally determines C
For example:{name, location, birthdate, time} {initials, age} implies that
{name, location, birthdate, time} {initials} and
{name, location, birthdate, time}{age}
8/8/2019 Ab Normalization Upload
10/26
Trivial
Functional Dependencies
Some functional dependencies are said to be trivial
because they are satisfied by all relation.
For example:
A A
X Y if Y is a subset of X
8/8/2019 Ab Normalization Upload
11/26
8/8/2019 Ab Normalization Upload
12/26
What is Superkey?
(review)
A superkey is defined in the relational model as a
set of attributes of a relation for which it holds that
in all instances of the relation there are no two
distinct tuples that have the same values for the
attributes in this set.
Equivalently a superkey can also be defined asthose sets of attributes of a relation upon which all
attributes of the relation are functionally dependent.
8/8/2019 Ab Normalization Upload
13/26
Keys and Functional
Dependencies(cont.)
Functional dependencies allow us to express constraints
that we cannot express with superkeys.
Let's consider the schema of the example in the
textbook(p.265) Figure 7.2
8/8/2019 Ab Normalization Upload
14/26
.
.
.
L-100..
.
loan_number amount
.
.
.
10000..
.
loan
.
.
.
23-652
15-20223-521.
.
.
customer_id loan_number
.
.
.
L-100
L-100L-100.
.
.
borrower
.
.
.
23-652
15-20223-521..
.
customer_id loan_number
.
.
.
L-100
L-100L-100.
.
.
amount
.
.
.
10000
1000010000.
.
.
bor_loan
Partial list of tuples in relations loan, borrower, and bor_loan
8/8/2019 Ab Normalization Upload
15/26
Keys and Functional
Dependencies(contd.)
In previous figure, we consider the schema
bor_loan = (customer_id, loan_number, amount)
in which the functional dependency loan_number amountholdsbecause for each loan (identified by loan_number) there is a
unique amount. We denote the fact that the pair ofattributes(customer_id, loan_amount) forms a superkey for
bor_loan by writing:
customer_id, loan_number customer_id, loan_number, amount
or, equivalently,
customer_id, loan_number
bor_loan
8/8/2019 Ab Normalization Upload
16/26
Keys and Functional
Dependencies(cont.)We shall use functional dependencies in two ways:
1. To test relations to see whether they are legal under
a given set of functional dependencies. If a relation ris a legal under a setFof functional dependencies,
we say that rsatisfies F.
2. To specify constraints on the set of legal relations.
We shall thus concern ourselves with only thoserelations that satisfy a given set of functional
dependencies. If we wish to constrain ourselves
to relations on schemaR that satisfy a setFof
functional dependencies, we say thatFholds onR.
8/8/2019 Ab Normalization Upload
17/26
Database Normalization
Database normalization relates to reducing redundancy.
The key idea is to reduce the chance ofhaving multipledifferent versions ofthe same data, like degree, by storingall potentially duplicated data in different tables and linking
to them instead of using a single copy. Then updating thedegree in one place will instantly change all the placeswhere the degree is used.
updates can be quickly performed with little risk ofdata becoming inconsistent.
.
8/8/2019 Ab Normalization Upload
18/26
Normal Forms
In the relational model, formal methods exist
to quantify "how to normalize a database ".
Such classifications are called normal forms,
and there are algorithms for converting a givendatabase between them.
Edgar F. Codd originally established 3 normal
forms:1NF, 2NF and 3NF.But 3NF is widely considered to be sufficient for
many practical applications. Most tables when
reaching 3NF are also in BCNF.
Normal Forms
8/8/2019 Ab Normalization Upload
19/26
1NF(First Normal Form)
In the relational model, we formalize this idea that
attributes do not have any substructure. A domain
is atomic if elements of the domain are consideredto be indivisible units. We say that a relation schema
R is in first normal form if the domains of all
attributes ofR are atomic.
1NF(First Normal Form)
In the relational model, we formalize this idea that
attributes do not have any substructure. A domain
is atomic if elements of the domain are consideredto be indivisible units. We say that a relation schema
R is in first normal form if the domains of all
attributes ofR are atomic.
8/8/2019 Ab Normalization Upload
20/26
1NF(First Normal Form)
To understand first normal form (1NF),consider these two examples of things you might know:
"What is your favourite colour?""What food will you not eat?"
Note difference between these two examples is that, you
can have only one favourite colour; but, little limitation on thenumber of foods you might not eat.
Data that has a single value such as "person's favourite
colour" is inherently in first normal form. Storing suchdata has not much changed since Codd wrote and needs
no further explanation here. Data that has multiple valuesmust be stored differently.
8/8/2019 Ab Normalization Upload
21/26
2NF(Second Normal Form)
Second normal form (2NF) prescribes full functional
dependancy on the primary key. It most commonly
applies to tables that have composite primary keys,
where two or more attributes comprise the primary key.It requires that there are no non-trivial functional
dependencies of a non-key attribute on a part (subset)
of a candidate key.
A table is said to be in the 2NF if and only if it is in the
1NF and every non-key attribute is irreducibly
dependent on the primary key.
8/8/2019 Ab Normalization Upload
22/26
2NF(Second Normal Form)
(cont.)How about this example?
Example:Machine_parts(part_number,supplier_name, price,supplier_address)
In this case, price is fully dependent on the primary
key(different suppliers may charge different price
on the same part).
However,supplier_address is partially dependent
because it only depends on thesupplier_name.
Therefore, this table is not in 2NF.
8/8/2019 Ab Normalization Upload
23/26
3NF(Third Normal Form)
Third normal form (3NF) requires that there are no
non-trivial functional dependencies of non-key
attributes on something other than a superset of a
candidate key.
A table is in 3NF if it is in 2NF, and none of the non-
primary key attributes is a fact about any other non-
primary key attribute.
In summary, all non-key attributes are mutually
independent(i.e. there should not be transitive
dependencies).
8/8/2019 Ab Normalization Upload
24/26
3NF(Third Normal Form)
(cont.)How about this example?
Example:Machine_parts(part_number,supplier_name,supplier_address)
In this case, supplier_address is dependent on
supplier_name. Therefore, there is a transitivedependency in the table.
It means that it is not in 3NF.
8/8/2019 Ab Normalization Upload
25/26
BCNF
(Boyce-Codd Normal Form)Boyce-Codd normal form (orBCNF) requires that there are
no non-trivial functional dependencies of attributes onsomething else than a superset of a candidate key. At this stage,
all attributes are dependent on a key, a whole key and nothingbut a key (excluding trivial dependencies, like AA).
A table is said to be in the BCNF if and only if it is in the 3NF
and every non-trivial, left-irreducible functional dependencyhas a candidate key as its determinant.
In more informal terms, a table is in BCNF if it is in 3NF andthe only determinants are the candidate keys.
8/8/2019 Ab Normalization Upload
26/26
Work Cited:
Silberschatz, Avi. HankKorth, and S. Sudarshan.
DATABASE SYSTEM CONCEPTS FIFTH
EDITION. New York:The McGraw-Hill
Companies, Inc., 205. 263-309.
Wikipedia: