Case Example


This chapter contained an example of Cascade Delete Related Records using three tables in the Northwind database. The example was complicated, so instead of having you perform the steps, I gave you a narrative. Now that you understand how Cascade Delete Related Records works, you might like some hands-on experience in this area:

1.

In the copy of the Northwind database you made in the "Cascade Update Related Fields" section, choose Tools, Relationships to display the Relationships window. (If you haven't done that exercise, follow the instructions in step 1 to make a copy of Northwind.mdb.)

Note that there is a one-to-many relationship between Categories and Products, as well as a one-to-many relationship between Products and Order Details.

2.

Double-click the line between Categories and Products.

3.

Select Cascade Delete Related Records. Click OK.

4.

Double-click the line between Products and Order Details. In the Edit Relationships dialog box, note that referential integrity is enforced, but the Cascade Delete Related Records is not selected.

5.

Click Cancel. Minimize the Relationships window.

6.

If necessary, maximize the Database window. Open the Products table.

7.

Select the Category column. Click the A-Z button for an Ascending Sort. Note that several products are beverages.

8.

Close the Products table. Click Yes to save your design changes.

9.

In the Database window, open the Categories table.

10.

Attempt to delete the Beverages record. Access won't let you delete the record because there are related records in the Order Details table. Categories and Order Details do not have a direct relationship. But Products and Order Details do, and Cascade Delete Related Records is not implemented. Thus, you cannot delete a record in the Categories table that has related records in the Products table because the Products table has related records in the Order Details table and referential integrity is enforced.

11.

Press Escape and close the Categories table.

12.

Maximize the Relationships window.

13.

Right-click the line between Products and Order Details, and select Edit Relationship.

This is another way of opening the Edit Relationships dialog box.

14.

Select Cascade Delete Related Records and click OK.

15.

Close the Relationships window. If you're asked to save the layout of the Relationships window, click Yes.

16.

Open the Order Details table. Select the Product field. Click the A-Z button for an ascending sort.

17.

Scroll down to note that many orders are for Chai, a beverage.

18.

Close the Order Details table. Click Yes to save your design changes.

19.

Open the Categories table.

20.

Delete the Beverages record.

Access warns you that you are about to delete one record as well as records in related tables.

21.

Click Yes to confirm the delete.

22.

Close the Categories table and open the Products table. Note that all the products with the category Beverages have been deleted.

23.

Close the Products table and open the Order Details table. Scroll down to note that all the records with Chai have been deleted. Close the Order Details table and close the database.




Hands-On Microsoft Access(c) A Practical Guide to Improving Your Access Skills
Hands-On Microsoft Access: A Practical Guide to Improving Your Access Skills
ISBN: 0321245458
EAN: 2147483647
Year: 2005
Pages: 169
Authors: Bob Schneider

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net