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 Relationship Types http://webcert.kirkwood.edu/~fmcclurg /courses/php/slides/chapter09c.relations hips.ppt

3 Relationship Types One to One Relationship One to Many Relationship Many to Many Relationship

4 user id first last shipping_id One to One Relationship Definition: One table is related to one and only one other table Example Schema:shipping id address city state zip

5 shipping id: 1 address: 524 N Laura Street city: Maryville state: MO zip: 64468 One to One Limitations User id: 3 first: Fred last: McClurg shipping_id: 2 Example Data: user id: 1 first: Wanda Lee last: McClurg shipping_id: 1 shipping id: 2 address: 1640 Fawn Drive city: North Liberty state: IA zip: 52317 shipping id: 3 address: 200 Hawkins Drive city: Iowa City state: IA zip: 52242 ????

6 One to One Relationship Considerations Note: 1.One to one relationships are rare 2.Consider eliminating one to one relationships by combining the columns into the same table

7 One to Many Relationship Definition: One table is related to many (one or more) other tables Schema Diagram: book id title author format_id format id type

8 format id type book id title author format_id book id title author format_id One to Many Relationship Definition: One table is related to many (one or more) other tables Example Schema:

9 One to Many Relationship (cont.)book id: 3 title: Expelled author: Ben Stein format_id: 4 format id: 4 type: DVD format id: 3 type: Paperback format id: 2 type: Hardback format id: 1 type: CD book id: 1 title: Dinner with a Perfect Stranger author: David Gregory format_id: 2 book id: 2 title: Dinner with a Perfect Stranger author: David Gregory format_id: 1 book id: 4 title: Learning PHP & MySQL author: Davis, Phillips format_id: 3 Example Data:

10 Many to Many Relationship Definition: Two (or more) tables are related to two (or more) other tables Schema Diagram: book id title author order id placed

11 Many to Many Relationship (cont.)order_to_book id order_id book_id Example Data:book id title author order id placed

12 Many to Many Data Example order_to_book id: 1 order_id: 1 book_id: 1 User: Fred Order: 1 Purchase: 2 itemsbook id: 1 title: My Life as Crocodile Junk Food order id: 1 placed: 2-4-2008 user_id: 1 order id: 2 placed: 1-9-2009 user_id: 2 book id: 3 title: Fireproof book id: 2 title: Soon book id: 4 title: Babylon Rising order_to_book id: 2 order_id: 1 book_id: 2 user id: 1 first: Fred last: McClurg order_to_book id: 3 order_id: 2 book_id: 3 order_to_book id: 4 order_id: 2 book_id: 4 user id: 2 first: Martha last: McClurg User: Martha Order: 2 Purchase: 2 items

13 to be continued... http://webcert.kirkwood.edu/~fmcclurg/cour ses/php/slides/chapter09d.normalization.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