This post follows from the post: Creating & using a “lookup table” in Access. In that exercise, we created a table with the details of some Learners, tblLearners, and a table with a list of unique suburb names, tblSuburbs. We then used tblSuburbs as the Row Source for the Suburbs field Combo Box in tblLearners.

1. Referential Integrity

This approach introduces an interesting problem: what happens if you delete a record from the Suburbs table where the specific Suburb deleted was actually being used as the suburb value for one of the records in tblLearners? Doing this would result in orphan records in the tblLearners table which would, in turn, mean your data is incomplete. To prevent this from happening, modern relational databases implement referential integrity.

2. Partner up

To enforce referential integrity, we must first create a relationship between two tables:

  1. Select the Database Tools menu tab
  2. Click on the Relationships button
  3. Click on the Show Table button
  4. Add the tblLearners and tblSuburbs tables

3. Create a relationship

The relationship is created by linking the tables using one field from each table:

  • The fields MUST have the same Data Type.
  • The fields do NOT have to have the same names.

Left-click-drag the suburbID field in tblSuburbs and drop it onto the Suburb field in tblLearners. The Edit Relationships dialog window will pop up.

4. Enforce Referential Integrity

Check the Enforce Referential Integrity checkbox and click the Create button. The screenshot below now shows the relationship between the two tables. The digit 1 (one) and the symbol (many) are to indicate that this is a one-to-many relationship between the tblSuburbs and tblLearners tables. This relationship describes the real-world scenario: a suburb only appears one time in the tblSuburbs table while it can appear many times in the tblLearners table — a suburb only exists once in reality — and many learners can live in the same suburb.

4. Test

Ensure that the suburbs have been selected for the learners in tblLearners and then attempt to delete a record for a suburb that is in use from tblSuburbs, the lookup table:

Open the lookup table, tblSuburbs, and notice that the relationship is further demonstrated with the expand/collapse button to the left of each record which displays related records from tblLearners. How cool is that?

By MisterFoxOnline

Mister Fox AKA @MisterFoxOnline is an ICT, IT and CAT Teacher. He has a passion for technology and loves to find solutions to problems using the skills he has learned in the course of his IT career.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from stylus

Subscribe now to keep reading and get access to the full archive.

Continue reading