Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relationships While we are on the subject of Relationships, let’s take a quick look at them.

Similar presentations


Presentation on theme: "Relationships While we are on the subject of Relationships, let’s take a quick look at them."— Presentation transcript:

1 Relationships While we are on the subject of Relationships, let’s take a quick look at them.

2 Relationships Remember or example about the customer and order tables?
One Customer, hopefully many orders?

3 In this example, we have two tables, the Customer table and the Orders table. The relationship between the two is a “One to Many” relationship because there is “One” record for each customer (no duplicate customers) in the Customer table and hopefully “Many” of the same Customer in the Orders table representing many orders from each customer. Customer Table Orders Table

4 “One” customer, hopefully “Many” orders is a “One-to-Many” relationship.
Customer Table Orders Table

5 Relationships We can join the two tables together by joining the common field in the One Side, [Customer].[CustomerNum] to the common field in the Many Side, [ Order].[CustomerNum].

6 Relationships To do that, we start at the database window, select Tools from the Menu Bar and then select Relationships.

7 Relationships From the resulting “Relationships” window, we select Relationships, and Show Table ...

8 Relationships From the resulting “Show Table” window, we select Our “One Side” table (customers in this case), and then click “Add”.

9 Relationships We then select our “Many Side” table, (order in this case) and then again click “Add”.

10 Relationships Then, simply click the Close Button.

11 Relationships We will then be back to our Relationships window with the Customer and Order tables showing.

12 To create a relationship (join), click on the common field (CustomerNum) in the One Side (left side), hold the button down, and drag to the common field (CustomerNum) in the Many Side (Order Table) and release the button.

13 As soon as we release the mouse button on top of the CustomerNum field in the Order Table, the Edit Relationships window appears. This window first, gives us a chance to verify that we selected the correct fields and the ability to change them if we did not.

14 We then can “Enforce Referential Integrity” if we so desire by simply clicking in the “Enforce Referential Integrity” check box.

15 Just what is Referential Integrity?
Simply put, using an example, if you have Referential Integrity enforced, when you enter a customer number in your order table, and that customer number does not exist in your customer table, Access will will give you a message saying that you can not enter that customer number as it does not exist in the customer table.

16 If we choose to “Enforce Referential Integrity” we then have two more options available to us, Cascade Update Related Fields and Cascade Delete Related Records.

17 If you select the Cascade Update Related Fields check box when defining a relationship, any time you change the primary key of a record in the primary table, Microsoft Access automatically updates the primary key to the new value in all related records. For example, if you change a customer's ID in the Customers table, the CustomerID field in the Orders table is automatically updated for every one of that customer's orders so that the relationship isn't broken. Microsoft Access cascades updates without displaying any message.

18 If you select the Cascade Delete Related Records check box when defining a relationship, any time you delete records in the primary table, Microsoft Access automatically deletes related records in the related table. For example, If you delete a customer record from the Customers table, all the customer's orders are automatically deleted from the Orders table (this includes records in the Order Details table related to the Orders records). When you delete records from a form or datasheet with the Cascade Delete Related Records check box selected, Microsoft Access warns you that related records may also be deleted.

19 However, when you delete records using a delete query, Microsoft Access automatically deletes the records in related tables without displaying a warning. We will be discussing delete queries in great detail in an upcoming class.

20 Notice Access automatically determines the Relationship type.

21 If you know that you have a one to many relationship, and this says you have a one-to-one relationship, check the fields above to make sure that you have selected the proper common field in both tables.

22 Relationships The final step is to click on the Create Button.

23 Relationships If we selected to “Enforce Referential Integrity” we will see a join line showing the one on the left and the infinity sign (many) on the right.

24 If we selected Not to “Enforce Referential Integrity” . . .

25 we will see a plain join line without the one on the left and the infinity sign (many) on the right.

26 Relationships The final step is to select File and then Save from the Relationships window.

27 Relationships and then select File and Close.


Download ppt "Relationships While we are on the subject of Relationships, let’s take a quick look at them."

Similar presentations


Ads by Google