First Normal Form: Functional Dependency

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

NORMALIZATION TO THIRD NORMAL FORM

FUNCTIONAL DEPENDENCY
Recap.
Third normal form. For attributes X and Y in a table, if it is invalid to have two identical values of
Normalising X with different values of Y
then Y is functionally dependent on X.
Reference:
X (The Determinant) - Key Field(s)
Connolly & Begg, Database Systems,
Y ...... - Non-Key Field(s)
Fifth Edition pp 365-387.
Eg
Fourth Edition pp 388-411.
Student number Student name

FIRST NORMAL FORM SECOND NORMAL FORM

Definition Definition
A table is in first normal form (1NF) if the intersection of each A table is in 2NF if it is in 1NF and every non-key attribute is
row with each column contains exactly one value. fully functionally dependant on any candidate key.
THIRD NORMAL FORM
Definition
A table is in 3NF if it is in 2NF and there are no transitive
dependencies of any non-key attributes on the key.

Transitive dependency:
attribute C depends transitively on attribute A if there is an
attribute B such that A → B, B → C

Name is transitively dependent on Film_id


THIRD NORMAL FORM THIRD NORMAL FORM
Definition Definition
A table is in 3NF if it is in 2NF and there are no transitive A table is in 3NF if it is in 2NF and there are no transitive
dependencies of any non-key attributes on the key. dependencies of any non-key attributes on the key.
Employee Department Location
Employee Department Location
Jones Grinding 3rd Floor
Jones Grinding 3rd Floor Smith Grinding 3rd Floor
Smith Grinding 3rd Floor Green Polishing 2nd Floor
Green Polishing 2nd Floor James Grinding 3rd Floor
James Grinding 3rd Floor Gray Finishing 3rd Floor
Gray Finishing 3rd Floor
Employee Department
Violates 3NF
- Location is location of department Department Location
ED
- Each department has one location
Employee Department DL
Problems:
- Redundancy Jones Grinding Department Location
- Update problems Smith Grinding
Green Polishing Grinding 3rd Floor
- Anomalies James Grinding Polishing 2nd Floor
- Storage of locations of departments without employees. Gray Finishing Finishing 3rd Floor

Functional Dependencies
Order
Ordnum Date Custnum Cname Caddress Prodnum Description Price Quant
The process of normalization:
1001 1/10/16 1122 Brown Stirling X2323 Taillight 166 1
S4545 Bulb 23 2
1. Write down the functional dependencies in each relation.
S2020 Connector 62 2
2. Separate out repeating fields. Make sure that each relation contains the key of 1002 1/10/16 1122 Brown Stirling S4545 Bulb 23 2
the original relation and sufficient other attributes to uniquely identify each F4545 Connector 62 1
tuple.
1003 1/11/16 3232 Brown Stirling F4545 Connector 62 2
3. Check that the functional dependencies do not violate 2nd Normal form D1212 Clip 62 1

4. Check that the functional dependencies do not violate 3rd Normal form
If it is invalid to have two identical values of X with different values of
Y then Y is functionally dependent on X. ie X Y
What functional dependencies can you deduce from the data in Order?
Anomalies First Normal Form
Order Order
Ordnum Date Custnum Cname Caddress Prodnum Description Price Quant Ordnum Date Custnum Cname Caddress Prodnum Description Price Quant
1001 1/10/16 1122 Brown Stirling X2323 Taillight 166 1 1001 1/10/16 1122 Brown Stirling X2323 Taillight 166 1
S4545 Bulb 23 2 S4545 Bulb 23 2
S2020 Connector 62 2 S2020 Connector 62 2
1002 1/10/16 1122 Brown Stirling S4545 Bulb 23 2 1002 1/10/16 1122 Brown Stirling S4545 Bulb 23 2
F4545 Connector 62 1 F4545 Connector 62 1
1003 1/11/16 3232 Brown Stirling F4545 Connector 62 2 1003 1/11/16 3232 Brown Stirling F4545 Connector 62 2
D1212 Clip 62 1 D1212 Clip 62 1

A table is in first normal form (1NF) if the intersection of each row


What happens to the addresses of customers who have no orders? (the with each column contains exactly one value.
price of parts that are not ordered?) How many different tables are needed for this? What are their
Is there redundant data? attributes? What about the primary keys? Can the tables be connected
by foreign key?

First Normal Form Second normal form


Order
A table is in 2NF if it is in 1NF and every non-key attribute is fully functionally
Ordnum Date Custnum Cname Caddress Prodnum Description Price Quant dependant on any candidate key.
1001 1/10/16 1122 Brown Stirling X2323 Taillight 166 1
Which table has a compound key? Are there attributes that are dependent on one
S4545 Bulb 23 2 or other of the attributes in the compound key?
S2020 Connector 62 2 How can the attributes be split so that they are in second normal form?
1002 1/10/16 1122 Brown Stirling S4545 Bulb 23 2 In 1NF but not in 2NF:
F4545 Connector 62 1
1003 1/11/16 3232 Brown Stirling F4545 Connector 62 2 T1 T2
D1212 Clip 62 1

T1
Functional Dependencies:
Ordnum -> Date, Custnum
T2 Custnum -> Cname, Caddress
Prodnum -> Description, Price
Ordnum, Prodnum -> Quant
Second normal form Second normal form
A table is in 2NF if it is in 1NF and every non-key attribute is fully functionally A table is in 2NF if it is in 1NF and every non-key attribute is fully functionally
dependant on any candidate key. dependant on any candidate key.
Which table has a compound key? Are there attributes that are dependent on one Which table has a compound key? Are there attributes that are dependent on one
or other of the attributes in the compound key? or other of the attributes in the compound key?
How can the attributes be split so that they are in second normal form? How can the attributes be split so that they are in second normal form?
In 1NF: In 1NF: In 2NF: T2.1
T2 T2

T2.2

Prodnum -> Description, Price Prodnum -> Description, Price


Ordnum, Prodnum -> Quant Ordnum, Prodnum -> Quant

Third normal form Third normal form

A table is in 3NF if it is in 2NF and there are no transitive dependencies of any A table is in 3NF if it is in 2NF and there are no transitive dependencies of any
non-key attributes on the key. non-key attributes on the key.
Are there attributes that are dependent on one or other of the attributes that are Are there attributes that are dependent on one or other of the attributes that are
not the key? not the key?
How can the attributes be split so that they are in third normal form? How can the attributes be split so that they are in third normal form?
T1 T1 T1.1

Functional Dependencies:
T2.1 Ordnum -> Date, Custnum T2.1
Custnum -> Cname, Caddress T1.2
T2.2 Prodnum -> Description, Price T2.2
Ordnum, Prodnum -> Quant
Third normal form Third normal form

In 3NF: In 3NF:

T2.1 T1.1 Order line Product Order


T2.2

T1.2 Customer

Normalisation and the ER model

Normalisation produces a set of table structures equivalent to those produced by Normalisation produces a set of table structures equivalent to those produced by
logical design. logical design.

By looking at the primary key/foreign key connections, it is possible to deduce By looking at the primary key/foreign key connections, it is possible to deduce
the structure to the ER model that would generate the logical design. Some the structure to the ER model that would generate the logical design. Some
assumptions are necessary. assumptions are necessary.

Order line Product Order Order line Product


Product

Customer
Order line
Normalisation and the ER model Normalisation and the ER model

Normalisation produces a set of table structures equivalent to those produced by Normalisation produces a set of table structures equivalent to those produced by
logical design. logical design.

By looking at the primary key/foreign key connections, it is possible to deduce By looking at the primary key/foreign key connections, it is possible to deduce
the structure to the ER model that would generate the logical design. Some the structure to the ER model that would generate the logical design. Some
assumptions are necessary. assumptions are necessary.

Order line Product Order line Product


Product Product

Ordered_on Ordered_on
Order line Order line

Order line Product Order Order line Product Order

Customer Customer

Product Product

Ordered_on Ordered_on
Order line Order line Order Customer
Has_item Placed
CS990 Database Fundamentals
CS952 Database & Web Systems Development

Databases content:

You might also like