Chapter 5: Normalizing the DB
What to do with a bad database structure? How do we determine the right structure? How do we determine primary keys? Normalization Rules.
Functional Dependence –When the values of one column depend on the values of another column –Column A determines Col B, then B is dependent on A. –If all the columns are dependent on A, then A is most likely a primary key.
RepNumLastNameFirstNameStreetCityStateZipCommissionPayClassRate 20KaiserValerie624 Randall GroveFL , HullRichard525 Jackson SheldonFL , PerezJuan1626 Taylor FillmoreFL , We’ve added a new field – Pay Class, which determines the rate. Rate is dependent on Pay Class. What other dependencies are there?
OrderNumOrderDateCustomerNum /20/ /20/ /21/ /21/ Orders Table The order number determines the date, and the customer number. They are dependent on the order number. The order number isn’t dependent on anything.
OrderNumPartNumNumOrderedQuotedPrice 21608AT DR DW DR What does the NumOrdered column depend on? What field(s) determine the quoted price?
1 st Normal Form: –Tables without repeating groups Break the repeating groups into individual rows to have 1 st Normal form.
Second Normal Form OrderNumOrderDatePartNumDescriptionNumOrderedQuotedPrice /20/2008AT94Iron /20/2008DR93Gase Range /20/2008DW11Washer /20/2008Kl62Dryer /23/2008DR93Gas Range What is wrong with this table structure? It is in 1NF, but not in 2NF.
The redundant data leads to serious problems. –Updating –Possibility of inconsistent data –Problem of making additions –Problem of deleting What is the primary key for that table? What does description depend on?
Third Normal Form CustomerNum CustomerName BalanceCreditLimitRepNumLastNameFirstName 148Al’s Appliance & Sport $6,550$7,50020KaiserValerie 282Brookings Direct $435$10,00035HullRichard 356Ferguson’s$ $7,50065PerezJuan 462Bargain’s Galore $3,412$10,00065PerezJuan CustomerNum determines everything. It’s the primary key. But there is still a problem… To get this table into 3NF, we need to break out the redundant data.
Fourth Normal Form FacultyNumStudentNumCommitteeCode ADV HSG PER HSG CUR If we redesigned this structure to this:
FacultyNumStudentNumCommitteeCode ADV HSG PER ADV HSG PER HSG CUR CUR This table is in 3NF, but what’s the problem here?
The table tries to group together 3 entities that really shouldn’t be grouped. They aren’t exactly related. What primary key column would determine the other column? It should be: FacStudent (FacultyNum, StudentNum) FacCommittee (FacultyNum, CommitteeCode)