Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization.

Similar presentations


Presentation on theme: "Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization."— Presentation transcript:

1 Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization

2 Objectives Discuss functional dependence and primary keys Define first normal form, second normal form, and fourth normal form Describe the problems associated with tables (relations) that are not in first normal form, second normal form, or third normal form, along with the mechanism for converting to all three Understand how normalization is used in the database design process 2

3 Introduction Normalization process –Identifying potential problems, called update anomalies, in the design of a relational database –Methods for correcting these problems Normal form: table has desirable properties –First normal form (1NF) –Second normal form (2NF) –Third normal form (3NF) 3

4 Introduction (continued) Normalization –Table in first normal form better than table not in first normal form –Table in second normal form better than table in first normal form, and so on –Goal: new collection of tables that is free of update anomalies 4

5 Functional Dependence A certain field say Column B is functionally dependent on another field say Column A if Column B’s value depend on the value of Column A. And also that Column A value is associated only with a exactly one value of Column B. And so if Column B depends on Column A then it also means that Column A functionally determines Column B. So, symbolically speaking it would look this: A → B (read as B is functionally dependent on A and A determines B) 5

6 Functional Dependence (continued) FIGURE 5-2: Rep table with additional column, PayClass 6 Let’s assume that in Premiere Products all Sales Rep in any given Pay class earn the Commission Rate. So, which means a Sale’s Rep Pay Class determines his/her Commission Rate And his/her Commission Rate therefore depends on his/her Pay Class

7 Functional Dependence (continued) 7 Let’s make it a local example here. Suppose we have a Courses table below: So, in this case Course Code determines his/her Course Description And Course Description depends on Course Code Course CodeCourse Description IS230Database Design CA100Computer Literacy BU101Intro to Business

8 Functional Dependence (continued) 8 Given a Salary table for Faculties of a community college which one field determines which field and which field depends which field? FacultyLevelPositionAnnual Salary 1Instructor16,000 2Assistant Professor19,000 3Associate Professor24,000 4Professor29,000 5Professor Emeritus35,000

9 Functional Dependence (continued) FIGURE 5-4: Rep table with second rep named Kaiser added FIGURE 5-3: Rep table 9

10 Question? Is Street functionally depend on Firstname or Lastname? 10

11 Question? Is CustomerName Functionally Dependent on RepNum? FIGURE 5-3: Rep table 11

12 Question? Is QuotedPrice Functionally Dependent on OrderNum? Is QuotedPrice Functionally Dependent on PartNum? So, on which columns does QuotedPrice is functionally dependent? FIGURE 5-3: Rep table 12

13 Non-Graded Exercise 13 Identify which field(s) is functionally dependent on which field(s) And then which field(s) functionally determines which field(s). Stud ID StudeLastStudFirstHighSchool Num HighSchool Name AdvisorNu m Advisor Name 1CruzJohn101CCA990Smith 2MooreAnna102SDA991Song 3FriendFe101CCA991Song 4ZapMario103MNHS990Smith 5BassGerard103MNHS992George

14 Primary Key and Functional Depedence 14 Remember the primary key concept that we learn on Chapter 3? Primary key uniquely identifies a record or row. The key in determining if column is functionally dependent to another column is to ask the question, is a certain column functionally dependent to the Primary Key.

15 Primary Key and Functional Depedence 15 Is Warehouse functionally dependent on Class? Is the Combination of Partnum and Descriptin is the Primary Key? What is the Primary Key of Part table?

16 Primary Key and Functional Depedence 16 Is CustomerNum the Primary Key for Customer table? Does CustomerNum determines the values of the other fields?

17 Question? Is OrderNum the Primary Key of OrderLine table? What is the Primary Key of OrderLine Table? FIGURE 5-3: Rep table 17

18 Nothing but the Key 18 The key thought in normalization is the primary key. To Quote E.F. Codd the father of relational database systems. –“[Every] non-key [attribute] must provide a fact about the key, the whole key, and nothing but the key.” Take this into mind as we go on three basic normal forms in Database Design.

19 First Normal Form There should be no repeating group or multi- valued columns in order for a Table to be in first normal form. –Repeating group: multiple entries for a single record –Unnormalized relation: contains a repeating group 19

20 First Normal Form (continued) Orders (OrderNum, OrderDate, (PartNum, NumOrdered) ) FIGURE 5-5: Sample unnormalized table 20 Repeating Group or Multi- valued Columns

21 First Normal Form (continued) Orders (OrderNum, OrderDate, PartNum, NumOrdered) FIGURE 5-6: Result of normalization (conversion to first normal form) 21

22 Second Normal Form (continued) Table (relation) in second normal form (2NF) –Table is in first normal form –No nonkey column (not a primary key) column should be partially dependent of a composite primary key. Partial dependencies: only on a portion of the primary key 22

23 Second Normal Form 23 Primary Key : OrderNum and PartNum Partially Depedent : OrderDate is partially dependent on OrderNum but not on both OrderNum and PartNum which are the composite Primary Key. Partially Depedent : Description is partially dependent on PartNum but not on both OrderNum and PartNum which are the composite Primary Key.

24 Second Normal Form (continued) FIGURE 5-9: Conversion to second normal form 24

25 Third Normal Form (continued) Table (relation) in third normal form (3NF) –It is in second normal form –There should no non-primary key that is transitional dependent to a primary key. 25

26 Third Normal Form (continued) FIGURE 5-10: Sample Customer table 26

27 Third Normal Form Customer (CustomerNum, CustomerName, Balance, CreditLimit, RepNum, LastName, FirstName) Functional dependencies: –CustomerNum → CustomerName, Balance, CreditLimit, RepNum, LastName, FirstName –RepNum → LastName, FirstName 27

28 Third Normal Form (continued) Correction procedure –Remove each column that is transitionally dependent. –Create a new table, transferring the removed columns to the newly created table. –Make a primary key of the new table –And use the primary key as the foreign key from the table where the columns were removed earlier. 28

29 Third Normal Form (continued) 29 FIGURE 5-12: Conversion to third normal form

30 Third Normal Form (continued) FIGURE 5-12: Conversion to third normal form (continued) 30

31 Incorrect Decompositions Decomposition must be done using method described for 3NF Incorrect decompositions can lead to tables with the same problems as original table 31

32 Incorrect Decompositions (continued) FIGURE 5-13: Incorrect decomposition of the Customer table 32

33 Incorrect Decompositions (continued) FIGURE 5-13: Incorrect decomposition of the Customer table (continued) 33

34 Incorrect Decompositions (continued) FIGURE 5-14: Second incorrect decomposition of the Customer table 34

35 Incorrect Decompositions (continued) FIGURE 5-14: Second incorrect decomposition of the Customer table (continued) 35

36 Guess which normal form it violates? 36 EmployeeIDLastnameFirstnameGenderComputer Skills 1JamesGeorgeMEncoding, MS Office, Photoshop 2MilesMayFEncoding, Programming, Database Design 3GatesAlanMProgramming, MS Office How should we normalized the above table? Let’s say we want to store Employee’s different computer skills on a table.

37 Guess which normal form it violates? 37 CustomerIDLastnameFirstnameContactNumber 1ChristopherRey320-1871, 320- 1584 2AllenGeorge320-1264 3GreenRhea320-1987, 320- 1574, 320-9874 How should we normalized the above table? Let’s say we want to store Customer’s contact numbers.

38 Guess which normal form it violates? 38 StudentIDCourseCo de LastnameFirstnameCourseDe scription Section 1001IS230MillsKarenDatabase Design 1 1002CA100CourtneyFrancisComputer Literacy 2 1003EN110SmithPhillipAdvanced Reading 5 1002EN110CourtneyFrancisAdvanced Reading 3 1004CA100MorrisonJohnComputer Literacy 2 How should we normalized the above table? Let’s say we want to store Students who takes courses on a particular section.

39 Guess which normal form it violates? 39 Semester Code Semester Year SemsterS eason StudentIDLastnameFirstname 2012-12012Spring1001MillsKaren 2012-12012Spring1002CourtneyFrancis 2012-32012Fall1003SmithPhillip 2012-32012Fall1004MorrisonJohn 2012-32012Fall1005DylanSarah How should we normalized the above table? Let’s say we want a table that stores those who enroll in a certain semester.

40 Guess which normal form it violates? 40 CourseCodeSectionFacultyIDLastnameFirstname IS23012001CastroEdper CA10042010MangononGeorge EN11013015RiveraMonica SS15021501HaglelgamJohn MS10013651Verg-inYenti How should we normalized the above table? Let’s say we want a table that stores the courses that Faculty taught.

41 Guess which normal form it violates? 41 DivisionIDDivisionNameFacultyIDLastnameFirstname 1Business1010Felix, Jr.Joseph 2Education1008HallersMaggie 3HCOP4025DacanayPaul 4Math and Science2641BizaSnyther How should we normalized the above table? Let’s say we want a table that stores who is the division chair of a certain division.

42 Graded Case Study – Alexamara 42 Problem 1 : Normalize the table below OwnerNumLastNameFirstNameBoatNameWeightMarina AD57AdneyBruce and JeanAdBruce X1,000 lbsEast Zinger1,500 lbsEast AN75AndersonBillYellow Beast2,000 lbsWest BL72BlakeMaryKumodo1,200 lbsEast Kryptonite1,000 lbsWest EL25ElendSandy and BillShark Fin1,300 lbsEast Two Cute900 lbsEast Ride North1,400 lbsWest

43 Graded Case Study - Alexamara 43 Problem 2 : Normalize the table below SlipIDMarinaNumSlipNumLengthRentalFeeBoatNameBoatTypeOwnerNumOwnerLastNameOwnerFirstName 11A140$3,800.00Anderson IISprite 4000AN75AndersonBill 21A240$3,800.00Our ToyRay 4025EL25ElendSand and Bill 31A340$3,600.00EscapeSprite 4000KE22KellyAllysa 41B130$2,400.00GypsyDolphin 28JU92JuarezMaria 51B230$2,600.00Anderson IIISprite 3000AN75AndersonBill 62125$1,800.00BravoDolphin 25AD57AdneyBruce and Jean 72225$1,800.00ChinookDolphin 22FE82FeenstraDaniel 82325$2,000.00ListyDolphin 25SM72SmeltzBeck and Dave 92430$2,500.00MermaidDolphin 28BL72BlakeMary 102540$4,200.00Axxon IIDolphin 40NO27NortonPeter 112640$4,200.00KarvelRay 4025TR72TrentAshton

44 Graded Case Study – Henry Books 44 Problem 1 : Normalize the table below PublisherCodePublisherNameCityBookTitleYearPublished AHArkham HouseSauk City WIDream House1999 Partial Recall2011 APArcade PublishingNew YorkGames Played1982 BABasic BooksBoulder CODance Fundamentals1980 Booking the Flight1993 BPBerkley PublishingBostonBastketball glory2001 VBVintage BooksNew YorkArchive Reload1998 Rusty Road2002 WNW.W. NortonNew YorkWar and Breeze2006 WPWestview PressBoulder COGeneral Goodwill1978

45 Graded Case Study – Henry Books 45 Problem 2 : Normalize the table below BookCodeTitleAuthorCodeAuthorFirstnameAuthorLastname 0180A Deepness in the Sky1001GeorgeGraham 0189Magic Terror1002EarlJohnson 0200The Stranger1001GeorgeGraham 0378Venice1003VitaliPablo 079XSecond Wind1004StrongMary 0808The Edge1002EarlJohnson

46 Summary Column (attribute) B is functionally dependent on another column A (or collection of columns) when each value for A in the database is associated with exactly one value of B Column(s) A is the primary key if all other columns are functionally dependent on A and no sub- collection of columns in A also have this property 46

47 Summary (continued) Table (relation) in first normal form (1NF) does not contain repeating groups Nonkey column (or nonkey attribute) is not a part of the primary key Table (relation) is in the second normal form (2NF) when it is in 1NF and no nonkey column is dependent on only a portion of the primary key Determinant is a column that functionally determines another column 47

48 Summary (continued) Table (relation) is in third normal form (3NF) when it is in 2NF and its only determinants are candidate keys Collection of tables (relations) that is not in third normal form has inherent problems called update anomalies 48


Download ppt "Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization."

Similar presentations


Ads by Google