Sie sind auf Seite 1von 5

CHAPTER 5

Functional Dependency & Normalization


Chapter Objectives:

In this chapter you will be able to:


1. Briefly describe functional dependency.
2. Use normalization to decompose a relation with anomalies into well-structured relations.

5.1. Definition of Terms


 FUNCTIONAL DEPENDENCY - a constraint between two attributes or two sets of attributes.
 NORMALIZATION – the process of decomposing relations with anomalies to produce smaller,
well-structured relations.
 NORMAL FORM – a state of a relation that results from applying simple rules regarding
functional dependencies.
 TRANSITIVE DEPENDENCY – a functional dependency between two (or more) nonkey
attributes.
 PARTIAL FUNCTIONAL DEPENDENCY – a functional dependency in which one or more nonkey
attributes are functionally dependent on part (but not
all) of the primary key.

5.2. Functional Dependency


 occurs when one attribute in a relation uniquely determines another attribute.
 this can be written A  B which would be the same as stating "B is functionally dependent upon
A."
Examples:
a. Emp_ID, Course_Title  Date_Completed
- the comma between Emp_ID and Course_Title stands for the logical AND operator
- the date a course is completed is determined by the identity of the employee and the title of the
course.
b. SSN  Name, Address, Birthdate
- an employee's name can be uniquely determined from their SSN.
- However, the reverse statement (name -> SSN) is not true because more than one employee can
have the same name but different SSNs.
c. VIN  Make, Model, Color
- a car's manufacturer, model and color can be uniquely determined from the vehicle identification
number.
5.3. Normalization
 is a formal process for deciding which attributes should be grouped together in a relation.
 is the process of efficiently organizing data in a database.
 is a database design technique which organizes tables in a manner that reduces redundancy and
dependency of data.
 There are two goals of the normalization process:
a. Eliminating redundant data (for example, storing the same data in more than one table)
b. Ensuring data dependencies (only storing related data in a table)

Both of these are worthy goals as they reduce the amount of space a database consumes and ensure
that data is logically stored.

5.3.1. First Normal Form


 First normal form (1NF) sets the very basic rules for an organized database:
 Eliminate duplicative columns from the same table.
o Any multi-valued attributes (also called repeating groups) have been removed, so there is
a single value at the intersection of each row and column of the table.

Example:

Emp_ID Name Dept_Name Salary Course_Title Date_Completed


100 Margaret Simpson Marketing 48,000 SPSS 6/19/2012
Surveys 10/27/2012
140 Alan Beeton Accounting 52,000 Tax Acct 12/8/2012
110 Chris Lucero Info Sys 43,000 VB 1/12/2013
C++ 2/14/2013
190 Lorenzo Davis Finance 55,000
150 Susan Martin Marketing 42,000 SPSS 6/16/2012

Fig. 5.3.1.a. : Table with repeating groups

Emp_ID Name Dept_Name Salary Course_Title Date_Completed


100 Margaret Simpson Marketing 48,000 SPSS 6/19/2012
100 Margaret Simpson Marketing 48,000 Surveys 10/27/2012
140 Alan Beeton Accounting 52,000 Tax Acct 12/8/2012
110 Chris Lucero Info Sys 43,000 VB 1/12/2013
110 Chris Lucero Info Sys 43,000 C++ 2/14/2013
190 Lorenzo Davis Finance 55,000
150 Susan Martin Marketing 42,000 SPSS 6/16/2012

Fig. 5.3.1.b. : Table with single valued attributes

Steps to Convert to 1NF


1. Remove repeating groups
2. Select the primary key
Anomalies in 1NF
a. Insertion Anomaly
b. Deletion Anomaly
c. Update Anomaly

Functional Dependency Diagram

Full Dependency

Emp_ID Name Dept_Name Salary Course_Title Date_Completed

Partial Dependencies Partial Dependency

5.3.2. Second Normal Form


 a relation is in 2NF if it is in 1NF, and contains no partial dependencies.
Steps to Convert to 1NF
1. Create a new relation for each primary key attribute. That attribute is the primary key in
the new relation.
2. Move the nonkey attributes that are dependent on this primary key attribute from the
old relation to the new relation.

EMPLOYEE
Emp_ID Name Dept_Name Salary

COURSE
Course_Title Date_Completed
A relation that is in 1NF will be in 2NF if any one of the following conditions applies:
1. The primary key consists of only one attribute.
2. No nonkey attributes exist in the relation (thus all of the attributes in the relation are
components of the primary key.
3. Every nonkey attribute is functionally dependent on the full set of primary key attributes.

5.3.3. Third Normal Form


 a relation is in 3rd NF if it is in 2nd NF and no transitive dependencies exist.
INVOICE
Order_ID Order_Date Cust_ID Cust_Name Cust_Add Prod_ID Prod_Desc Unit_Price Ordered_Qty
1006 10 / 24 / 12 2 CSI Dagupan 7 Colgate 56.75 2
1006 10 / 24 / 12 2 CSI Dagupan 5 Safeguard 13.50 2
1006 10 / 24 / 12 2 CSI Dagupan 4 Dove 5.25 1
1007 10 / 25 / 12 6 Magic Lingayen 11 Nescafe 34.75 4
1007 10 / 25 / 12 6 Magic Lingayen 4 Nido 118.25 3

Functional Dependency Diagram


Full Dependency

Transitive Dependency

Order_ID Order_Date Cust_ID Cust_Name Cust_Add Prod_ID Prod_Desc Unit_Price Ordered_Qty

Partial Dependencies Partial Dependencies

First Normal Form


INVOICE ( Order_ID, Prod_ID, Ordered_Qty )

Second Normal Form

ORDER_LINE ( Order_ID, Prod_ID, Ordered_Qty )


PRODUCT ( Prod_ID, Prod_Desc, Unit_Price, Ordered_City )
CUSTOMER_ORDER ( Order_ID, Order_Date, Cust_ID, Cust_Name, Cust_Add )
 Removing Transitive Dependencies
a. For each nonkey attribute (or set of attributes) that is a determinant in a relation, create a new
relation. That attribute (or set of attributes) becomes the primary key of the new relation.
b. Move all the attributes that are functionally dependent on the attribute from the old to the new
relation.
c. Leave the attribute (w/c serves as a primary key in the new relation) in the old relation to serve as a
foreign key that allows us to associate the two relations.

CUSTOMER_ORDER ( Order_ID, Order_Date, Cust_ID, Cust_Name, Cust_Add )


ORDER ( Order_ID, Order_Date, Cust_ID )
CUSTOMER ( Cust_ID, Cust_Name, Cust_Add )

Das könnte Ihnen auch gefallen