Presentation is loading. Please wait.

Presentation is loading. Please wait.

One Customer has Many Pets; One Pet as One Customer, so Customer ID goes on Pet Table. One Pet has many Visits, but only one Visit refers.

Similar presentations


Presentation on theme: "One Customer has Many Pets; One Pet as One Customer, so Customer ID goes on Pet Table. One Pet has many Visits, but only one Visit refers."— Presentation transcript:

1

2

3

4

5

6

7

8 One Customer has Many Pets; One Pet as One Customer, so Customer ID goes on Pet Table. One Pet has many Visits, but only one Visit refers to one Pet, so ONE’s ID goes on MANY’s Table. PetID goes on Visit Table.

9 One VISIT Can have MANY Procedures; the table as shown above limits the visit to having three. That would be OK—until you need more. If this refers to a specific procedure which could be described by another table, it is a one-to-many relationship and can have the VisitID as Foreign Key on the Procedure Table. No FK here CustID as FK PetID As FK VisitID as FK

10 Does CustomerNumber belong on the Product Table? NO

11 It was not on the Product Table. Note the Order Detail Table with TWO Primary Keys. When one ORDER could have many PRODUCTS and one PRODUCT can be on many Orders, this is a Many-to-Many Relationship.

12 Note the Order Detail Table with TWO Primary Keys. When one ORDER (ORDER TABLE) could have many PRODUCTS and one PRODUCT (PRODUCT TABLE) can be on many Orders, this is a Many-to-Many Relationship.

13 Join Types Type 1 Join – INNER JOIN Type 2 – LEFT OUTER JOIN Type 3 – RIGHT OUTER JOIN ABDEFHABDEFH BCDEFGBCDEFG ABDEFHABDEFH BCDEFGBCDEFG ABDEFHABDEFH BCDEFGBCDEFG RESULTS of these JOINS BDEFBDEF ABDEFHABDEFH BCDEFGBCDEFG Only fields where both tables match All fields of left table and only matching fields from right table All fields of right table and only matching fields from left table

14 Join Types from Chapter 9 Type 1 Join – INNER JOIN Type 2 – LEFT OUTER JOIN Type 3 – RIGHT OUTER JOIN ABDEFHABDEFH BCDEFGBCDEFG ABDEFHABDEFH BCDEFGBCDEFG ABDEFHABDEFH BCDEFGBCDEFG RESULTS of these JOINS BDEFBDEF ABDEFHABDEFH BCDEFGBCDEFG Only fields where both tables match All fields of left table and only matching fields from right table All fields of right table and only matching fields from left table

15 One-to-One Relationships exist when ONE item from the Primary Table will match only ONE item on the Secondary Table and ONE item in the Secondary Table will match only ONE item in the Primary Table. An example is Business Address and Mailing Address. One business will have mail either go to that same address (actual physical location is used for mailing) or sometimes to another address, such as a P. O. Box. This can be “handled” by a One-to-One relationship called an Entity Subtype. We’ll learn how to choose one rather than the other later by using Conditional IIF Statements. However, if you leave the default join type, INNER JOIN, you won’t have much data! Using this (where not all businesses use a P. O. Box for mail) requires us to use an Outer Join. If we have 100 businesses and only 20 of them have entries in this one- to-one relationship table and we have an “INNER JOIN,” which is what you get if you don’t SPECIFY it yourself, you’ll only see 20 businesses in your results! If you only mail out your flyers to that group, you have lost a lot of business! One-to-One Relationships

16

17 One-to-One Lookup One-to-Many Many-to-Many Details table with composite key Relationships

18

19

20 What do we need to do.doc


Download ppt "One Customer has Many Pets; One Pet as One Customer, so Customer ID goes on Pet Table. One Pet has many Visits, but only one Visit refers."

Similar presentations


Ads by Google