Lecture 5 - Normalization of Relational Tables
Lecture 5 - Normalization of Relational Tables
“Between two evils, choose neither; between two goods, choose both.”
Tryon Edwards
Steps to E-R Transformation
1. Identify entities
2. Identify relationships
3. Determine relationship type
4. Determine level of participation
5. Assign an identifier for each entity
6. Draw completed E-R diagram
7. Deduce a set of preliminary skeleton tables along with a
proposed primary key for each table (using rules provided)
8. Develop a list of all attributes of interest (not already
listed and systematically assign each to a table in such a
way to achieve a 3NF design (i.e., no repeating groups,
no partial dependencies, and no transitive dependencies)
Tables
Database design is the process of separating
information into multiple tables that are related to
each other
Single table designs work only for the simplest of
situations in which data integrity problems are
easy to correct
Anomalies (abnormalities) often arise in single
table designs as a result of inserting, deleting, or
updating records
Some tables are better structured than others (i.e.,
result in fewer anomalies)
Redundancy
Unnecessary repetition or duplication of data
increases likelihood of errors due to keying inconsistencies
Multi-valued Problems
Solution 1? Include all author’s names in a single field
Difficult to search for a single author’s name or create an
alphabetical list of authors
Multi-valued Problems
Solution 2? Add multiple columns, one for each value
empty fields waste storage space
awkward to search across fields (e.g., Any books by Snoopy? Must search Author1, Author2, etc.)
necessitates the creation of a new column every time a book has an additional author
Multi-valued Problems
Solution 3? Add multiple rows, one for each value
Data about a book must be repeated for as many times as there are authors of a book (also creates
redundancy which lead to keying errors and unnecessarily wasting storage space with large files)
count of total # of books or # from each publisher would be wrong
Update Anomalies
Update Anomalies
To update an agent’s telephone number, each instance must be
changed
if we miss an item or enter it incorrectly we create an unreliable
table
sometimes previous errors
propagate errors further
Deletion anomalies
What happens if a customer record is deleted?
What happens if an agent record is deleted?
Total: 3,124.50
Category Total Occurences
0
Accessories 2
2. Nulls used in aggregate functions
Bikes 1 - blanks exist under category
Components 1 - cannot be counted because they don’t exist!
Database Design Problems
Use of the relational database model removes
some database anomalies
Further removal of database anomalies relies on
a structured technique called normalization
Presence of some of these anomalies is
sometimes justified in order to enhance
performance
RENTALDETAILS
RENTAL (RentalNum, Cust_Num, Rental_date,
(RentalNum,
Return_Date, TotalPrice, Paid?)
VideoNum)
The Video Store is now in 1NF
Cust_Num Cust_Name Cust_address Cust_Phone CUSTOMER
1 Rodney Jones 23 Richmond St.681-9854
(Cust_Num, Cust_Name,
2 Francine Moire 750-12 Kipps Lane
672-9999
Cust_address,
3 Anne Abel 5 Sarnia Road 432-1120
Cust_phone
VideoNum VideoName VideoType
1 Gone with the Wind Classic
2
3
Manhatten
Never Say Never Again
Comedy
Adventure
VIDEO (VideoNum,
4 Braveheart Adventure VideoName, VideoType
5 Mississippi Burning Adventure
6 The African Queen Classic RentalNum VideoNum
7 Silence of the Lambs Horror 1 1
1 4
1 5
RentalNum Cust_Num Rental_date Return_date TotalPrice Paid? 2 2
1 1 15-Oct-99 17-Oct-99 $ 60.00 yes 3 2
2 2 4-Nov-99 3 6
3 3 3-Sep-99 4-Sep-99 $ 20.00 yes 4 3
4 1 22-Sep-99 26-Sep-99 $ 80.00 yes 4 7
RENTALDETAILS
RENTAL (RentalNum, Cust_Num, Rental_date,
(RentalNum,
Return_Date, TotalPrice, Paid?)
VideoNum)
Is the Video Store in 2NF?
The only table that has a composite primary key has no other fields, therefore, yes.
RentalNum VideoNum
VideoNum VideoName VideoType
1 1
1 Gone with the Wind Classic
1 4
2 Manhatten Comedy
1 5
3 Never Say Never Again
Adventure
2 2
4 Braveheart Adventure 3 2
5 Mississippi BurningAdventure 3 6
6 The African Queen Classic 4 3
7 Silence of the LambsHorror 4 7