Presentation is loading. Please wait.

Presentation is loading. Please wait.

Kirkwood Center for Continuing Education By Fred McClurg, Introduction to PHP and MySQL Copyright © 2010 All Rights Reserved.

Similar presentations


Presentation on theme: "Kirkwood Center for Continuing Education By Fred McClurg, Introduction to PHP and MySQL Copyright © 2010 All Rights Reserved."— Presentation transcript:

1 Kirkwood Center for Continuing Education By Fred McClurg, frmcclurg@gmail.com Introduction to PHP and MySQL Copyright © 2010 All Rights Reserved.

2 Chapter Nine Normalization http://webcert.kirkwood.edu/~fmcclurg/cour ses/php/slides/chapter09d.normalization.ppt

3 Normalization Defined: The breaking apart of data into logical relationships to reduce duplication of data. Why Normalize? 1.Reduce duplication 2.Conserve storage space 3.Reduce maintenance

4 Normalization (cont.) Avoid Extremes: 1.Each data column in a separate table A.Queries would be very large B.Additional processing time required 2.All columns in one table A.Data is repeated between rows B.Requires additional storage C.Updates on multiple rows required

5 Forms of Normalization (1NF) First Normal Form (1NF or FNF) Purpose: Reducing redundant data across a horizontal row Rules: 1.No multiple columns containing the same data 2.Column can contain only one value 3.The primary key must uniquely define the row

6 2 1 First Normal Form Challenge After Normalization: Rule One: Move multiple authors into a single table Rule Two: Break name into two separate columns Break address into four separate columns Rule Three: Add an unique id for a primary keyNameAddressPhoneTitleAuthor1Author2Ordered Fred McClurg 1640 Fawn Drive, North Liberty, IA 52317 319-123-4567The Case for a Creator Lee Strobel Garry Poole Jan 9, 2009 Fred McClurg 1640 Fawn Drive, North Liberty, IA 52317 319-123-4567More than a Carpenter Josh McDowell Jan 9, 2009 Before Normalization:

7 NameAddressPhoneTitleAuthor1Author2Ordered Fred McClurg 1640 Fawn Drive, North Liberty, IA 52317 319-123-4567The Case for a Creator Lee StrobelGarry Poole Jan 9, 2009 Fred McClurg 1640 Fawn Drive, North Liberty, IA 52317 319-123-4567More than a Carpenter Josh McDowell Jan 9, 2009 First Normal Form Results After Normalization Example:IDFirstLastAddressCityStateZipPhoneTitleOrdered 1FredMcClurg1640 Fawn Drive North Liberty IA52317319-123-4567The Case for a Creator Jan 9, 2009 2FredMcClurg1640 Fawn Drive North Liberty IA52317319-123-4567More than a Carpenter Jan 11, 2009 IDTitleAuthor 1The Case for a CreatorLee Strobel 2The Case for a CreatorGarry Poole 3More than a CarpenterJosh McDowell

8 Forms of Normalization (2NF) Second Normal Form (2NF) Purpose: Reducing redundant data in vertical columns Rules: 1.Tables must be in First Normal Form 2.Place columns that repeat values across multiple rows into a separate table 3.Place columns that aren’t dependent on the primary key into a separate table

9 IDFirstLastAddressCityStateZipPhoneTitleOrdered 1FredMcClurg1640 Fawn Drive North Liberty IA52317319-123-4567The Case for a Creator Jan 9, 2009 2FredMcClurg1640 Fawn Drive North Liberty IA52317319-123-4567More than a Carpenter Jan 11, 2009 IDTitleAuthor 1The Case for a CreatorLee Strobel 2The Case for a CreatorGarry Poole 3More than a CarpenterJosh McDowell Second Normal Form Challenge Before Normalization: After Normalization: Rule Two: Move book into separate table Rule Three: Move author into separate table Move orders into separate table

10 OrderUser_IDBook_IDPlaced 11Jan 9, 2009 12Jan 11, 2009 Second Normal Form ResultsIDFirstLastAddressCityStateZipPhoneTitleOrdered 1FredMcClurg1640 Fawn Drive North Liberty IA52317319-123-4567The Case for a Creator Jan 9, 2009 2FredMcClurg1640 Fawn Drive North Liberty IA52317319-123-4567More than a Carpenter Jan 11, 2009 IDTitleAuthor 1The Case for a CreatorLee Strobel 2The Case for a CreatorGarry Poole 3More than a CarpenterJosh McDowellBook IDTitle 1The Case for a Creator 2More than a Carpenter AuthorIDName 1Lee Strobel 2Garry Poole 3Josh McDowell Book_to_AuthorBook_IDAuthor_ID 11 12 23 IDFirstLastAddressCityStateZipPhone 1FredMcClurg1640 Fawn Drive North Liberty IA52317319-123- 4567

11 What is the relationship between address, city, state, and zip? Address, City, State, Zip Relationshipaddressidstreetcity_id 1Kansas State University1 2Empire State Building2 3Grand Central Station3 state idnamezip_id 1KS1 2NY2 3 3city idnamestate_id 1Manhattan1 2 2 3 3zip idcode 166506 210018 310017 address city state zip

12 What is the relationship between address, city, state, and zip? Address, City, State, Zip Relationship address idstreetstate_id 1Kansas State University1 2Empire State Building2 3Grand Central Station3 state idnamecity_id 1KS1 2NY2 3 3 city idnamezip_id 1Manhattan1 2 2 3 3 zip idcode 166506 210018 310017 address state city zip

13 zipidcodestate_id 1665061 2100182 3100172 What is the relationship between address, city, state, and zip? Address, City, State, Zip Relationshipaddressidstreetcity_id 1Kansas State University1 2Empire State Building2 3Grand Central Station3 stateidname 1KS 2NYcityidnamezip_id 1Manhattan1 2 2 3 3 address city zip state

14 What is the relationship between address, city, state, and zip? Address, City, State, Zip Relationshipaddressidstreetzip_id 1Kansas State University1 2Empire State Building2 Grand Central Station3 stateidname 1KS 2NY cityidnamestate_id 1Manhattan1 2 2zipidcodecity_id 1665061 2100182 3100172 address zip city state

15 What is the relationship between address, city, state, and zip? Address, City, State, Zip Relationshipaddress idstreetzip_id 1Kansas State University1 2Empire State Building2 3Grand Central Station3 state idname 1KS 2NY city idname 1Manhattan zip idcodecity_idstate_id 16650611 21001812 31001712 address zip city state

16 Forms of Normalization (cont.) Third Normal Form (3NF) Purpose: Reduce data that is not dependant on the primary key, but is dependant on other data in the table Note: The Third Normal Form process may not be necessary if First and Second Normal Form process has been performed. (refinement of 1NF and 2NF)

17 IDFirstLastAddressCityStateZipPhone 1FredMcClurg1640 Fawn Drive North Liberty IA52317319-123-4567 Book_to_AuthorBook_IDAuthor_ID 11 12 23 OrderUser_IDBook_IDPlaced 11Jan 9, 2009 12Jan 11, 2009 Third Normal Form ProblemUsers ID 1 First Fred Last McClurg Address 1640 Fawn Drive Zip_ID 1 Phone 319-123-4567Zip ID 1 Code 52317 City_ID 1 State_ID 1 City ID 1 Name North LibertyState ID 1 Abbrev IA BookIDTitle 1The Case for a Creator 2More than a Carpenter AuthorIDName 1Lee Strobel 2Garry Poole 3Josh McDowell

18 Denormalization Quote: “Normalize until it hurts. Denormalize until it helps.” Description: Normalization often involves separating data into tables. Denormalization is the process of grouping data together.

19 Denormalization (cont.) Book IDTitleISBN_ID 1Dinner with a Perfect Stranger 1 2A Day with a Perfect Stranger 2 ISBN IDCode 11578569052 21400072425 Book IDTitleISBN 1Dinner with a Perfect Stranger 1578569052 2A Day with a Perfect Stranger 1400072425

20 to be continued... http://webcert.kirkwood.edu/~fmcclurg/cour ses/php/slides/chapter09e.performance.ppt


Download ppt "Kirkwood Center for Continuing Education By Fred McClurg, Introduction to PHP and MySQL Copyright © 2010 All Rights Reserved."

Similar presentations


Ads by Google