Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Chapter 5: Normalizing the DB

2 What to do with a bad database structure? How do we determine the right structure? How do we determine primary keys? Normalization Rules.

3 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.

4 RepNumLastNameFirstNameStreetCityStateZipCommissionPayClassRate 20KaiserValerie624 Randall GroveFL3332120,542.501.05 35HullRichard525 Jackson SheldonFL3355339,216.002.07 65PerezJuan1626 Taylor FillmoreFL3333623,487.001.05 We’ve added a new field – Pay Class, which determines the rate. Rate is dependent on Pay Class. What other dependencies are there?

5 OrderNumOrderDateCustomerNum 2160810/20/2010148 2161010/20/2010356 2161310/21/2010408 2161410/21/2010282 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.

6 OrderNumPartNumNumOrderedQuotedPrice 21608AT941121.95 21610DR931495.00 21610DW111399.00 21613DR934329.00 What does the NumOrdered column depend on? What field(s) determine the quoted price?

7 1 st Normal Form: –Tables without repeating groups Break the repeating groups into individual rows to have 1 st Normal form.

8 Second Normal Form OrderNumOrderDatePartNumDescriptionNumOrderedQuotedPrice 2160810/20/2008AT94Iron1121.95 2161010/20/2008DR93Gase Range1495.00 2161010/20/2008DW11Washer1399.00 2161310/20/2008Kl62Dryer4329.00 2161910/23/2008DR93Gas Range1495.00 What is wrong with this table structure? It is in 1NF, but not in 2NF.

9 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?

10 Third Normal Form CustomerNum CustomerName BalanceCreditLimitRepNumLastNameFirstName 148Al’s Appliance & Sport $6,550$7,50020KaiserValerie 282Brookings Direct $435$10,00035HullRichard 356Ferguson’s$5785.00$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.

11 Fourth Normal Form FacultyNumStudentNumCommitteeCode 12312805 24139 ADV HSG PER 44457384HSG 45624139 36273 37573 CUR If we redesigned this structure to this:

12 FacultyNumStudentNumCommitteeCode 12312805ADV 12312805HSG 12312805PER 12324139ADV 12324139HSG 12324139PER 44457384HSG 45624139CUR 45636273CUR This table is in 3NF, but what’s the problem here?

13 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)


Download ppt "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."

Similar presentations


Ads by Google