Introduction to Access97 (2): Relationships. by Robin Beaumont. Contents 2. LEARNING OUTCOMES CHECK LIST FOR THE SESSION...2 3. INTRODUCTION...



Similar documents
Introduction to LibreOffice Base (LOB)-2. Relationships. Robin Beaumont Date: Saturday, 07 April

Object models and Databases. Contents

MICROSOFT ACCESS TABLES

Topic: Relationships in ER Diagram and Relationships in MS Access

Ken Goldberg Database Lab Notes. There are three types of relationships: One-to-One (1:1) One-to-Many (1:N) Many-to-Many (M:N).

In this example, Mrs. Smith is looking to create graphs that represent the ethnic diversity of the 24 students in her 4 th grade class.

Microsoft Word 2010: How to Resize and Move Clip Art

Look in the top right of the screen and located the "Create an Account" button.

From Data Modeling to Data Dictionary Written Date : January 20, 2014

Introduction to Microsoft Access 2003

Microsoft Excel 2013: Using a Data Entry Form

Planning and Creating a Custom Database

Creating Calculated Fields in Access Queries and Reports

Microsoft Access 2010 handout

Drawing a histogram using Excel

Simple Invoicing Desktop Database with MS Access c 2015 by David W. Gerbing School of Business Administration Portland State University

Creating Fill-able Forms using Acrobat 8.0: Part 1

Creating Tables ACCESS. Normalisation Techniques

Microsoft Office 2010

Microsoft Word 2010 Mail Merge (Level 3)

Intellect Platform - Tables and Templates Basic Document Management System - A101

Creating Survey Forms from a Word Table

Microsoft Access Basics

Advanced Presentation Features and Animation

Creating a Newsletter with Microsoft Word

Microsoft Word Track Changes

Excel basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

Working with SmartArt

Excel Spreadsheet Activity Redo #1

Division of School Facilities OUTLOOK WEB ACCESS

MICROSOFT WORD TUTORIAL

Appointments: Calendar Window

Creating trouble-free numbering in Microsoft Word

Computer Training Centre University College Cork. Excel 2013 Level 1

Use Find & Replace Commands under Home tab to search and replace data.

Creating tables in Microsoft Access 2007

Using an Access Database

Create a report with formatting, headings, page numbers and table of contents

Tutorial: Creating a form that s the results to you.

Filter by Selection button. Displays records by degree to which they match the selected record. Click to view advanced filtering options

PowerPoint 2013 Basics of Creating a PowerPoint Presentation

Access Creating Databases - Fundamentals

PEMBINA TRAILS SCHOOL DIVISION. Information Technology Department

PA Payroll Exercise for Intermediate Excel

INTRODUCTION TO MICROSOFT ACCESS MINIMAL MANUAL

Using SQL Server Management Studio

Getting Started with Excel Table of Contents

paragraph(s). The bottom mark is for all following lines in that paragraph. The rectangle below the marks moves both marks at the same time.

Computer Training Centre University College Cork. PowerPoint 2013

Access 2010 Intermediate Skills

Introduction to MS WINDOWS XP

LEARNING RESOURCE CENTRE. Guide to Microsoft Office Online and One Drive

Microsoft Word 2010 Tutorial

Entering the example employee satisfaction survey in Survey Crafter Professional s Survey Designer window

Fleet Maintenance Software

MICROSOFT ACCESS STEP BY STEP GUIDE

Microsoft Excel 2007 Consolidate Data & Analyze with Pivot Table Windows XP

In this session, we will explain some of the basics of word processing. 1. Start Microsoft Word 11. Edit the Document cut & move

Handout: Word 2010 Tips and Shortcuts

Microsoft Access 2010

Converting SQLBase Databases to Microsoft Access

Joomla! 2.5.x Training Manual

Microsoft PowerPoint 2010 Computer Jeopardy Tutorial

Microsoft Access 2010 Overview of Basics

How To Insert Hyperlinks In Powerpoint Powerpoint

AODA Mouse Pointer Visibility

Creating Database Model Diagrams in Microsoft Visio Jeffery S. Horsburgh

Business Objects. Report Writing - CMS Net and CCS Claims

Microsoft Using an Existing Database Amarillo College Revision Date: July 30, 2008

Microsoft Access Part I (Database Design Basics) ShortCourse Handout

Microsoft Office 2010: Introductory Q&As PowerPoint Chapter 1

Weebly.com First Steps

Web Ambassador Training on the CMS

Making an online form in Serif WebPlus

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Introduction. Inserting Hyperlinks. PowerPoint 2010 Hyperlinks and Action Buttons. About Hyperlinks. Page 1

How to make a line graph using Excel 2007

Creating Database Tables in Microsoft SQL Server

Steps to Create a Database

Basic tutorial for Dreamweaver CS5

Working With Microsoft PowerPoint

CATIA Basic Concepts TABLE OF CONTENTS

Using Google Docs in the classroom: Simple as ABC

Working with Tables. Creating Tables in PDF Forms IN THIS CHAPTER

Instructions for Creating Silly Survey Database

Use signatures in Outlook 2010

Version 4.1 USER S MANUAL Technical Support (800)

Introduction to Word 2007

Access 2007 Creating Forms Table of Contents

Introduction to ERD modelling using UML Class diagrams with Magicdraw (ver 17)

Monthly Payroll to Finance Reconciliation Report: Access and Instructions

Analyzing Excel Data Using Pivot Tables

CheckBook Pro 2 Help

Working with Visio Connectors

A Quick Start Guide to Using PowerPoint For Image-based Presentations

This course covers the following topics:

QUICK START GUIDE RESOURCE MANAGERS. Last Updated: 04/27/2012

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

Transcription:

Introduction to Access97 (2): Relationships by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk Contents 2. LEARNING OUTCOMES CHECK LIST FOR THE SESSION...2 3. INTRODUCTION...3 4. RELATIONSHIPS IN ACCESS...3 5. CREATING RELATIONSHIPS...5 5.1 Saving relationships...8 6. WHAT ADDING REFERENTIAL INTEGRITY DOES WHEN ENTERING DATA...9 7. AN INTRODUCTION TO DEPENDENCY...12 8. SUMMARY...13 9. CHECK WHAT YOU HAVE LEARNT...13 This handout is part of a course. For details please see Section 7.1 at: http://robinbt2.free-online.co.uk/virtualclassroom/contents.htm

2. Learning outcomes check list for the session This practical session aims to provide you with the following skills (the 'be able to's' below) and information (the 'know what's' below). After you have completed the session you should come back to these points ticking off those you feel happy with. Learning outcome Be able to create foreign keys in Access. Be able to use the Relationships window Be able to set the appropriate options in the relationships dialogue box to enforce 'referential integrity' Be able to Create, edit and save relationships in Access Understand the concept of dependency (referential integrity) and the effects this has when adding, editing or deleting records Tick box Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 2

3. Introduction During the last Access session we created the tables for the consultations database giving it the Access database name Cons1. During this session we will carry on developing it further by adding relationships between tables. You should have worked through 'Section 7.3 Relationships', to have gained an understanding of the relationships concepts, before completing this practical session. 4. Relationships in Access When we created the six tables that make up the consultations database in the last session we added the necessary foreign keys to the tables. What has this done exactly? Open up the cons1 database you created. Open up the patient table You should now be in datasheet view (the view that shows the contents of each record) rather than design view. If you not move now to the correct view (for details see previous practical sessions notes). You should have one record in the patient table (if not please add it): Field Name Value to add: ID 1 Title Mr First Name john Surname smith Doc ID 100 DOB 01/01/68 Key Point: Remember the database does not know about the data you enter into a field until you have moved to another record or clicked 'save'. Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 3

Move look at the doctor table. Does such a doc. ID value exist? What conclusions can you draw? Could this situation exist in reality? The above exercise demonstrates clearly that just adding foreign keys to a table does not ensure that the computer adheres to the foreign key principle (i.e. foreign key values can only be those that already exist as a primary key in the referencing field). Luckily the DBMS (Database Management System), Access, provides a 'relationships' facility to ensure we do not end up in the situation demonstrated above. Key point: Adding foreign key fields to tables does nothing to ensure that the values in them actually exists in the master table where they are the key. To do this you need to set up 'relationships' in the DBMS. Delete the record in the patient table. (for details refer back to the last practical sessions material). Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 4

5. Creating relationships This is achieved in Access97 by using the 'Relationships Window '. Introduction to Health Informatics Adding tables to the relationships window Make sure you have the cons1 database open. Make sure you have deleted any records in the Doctor and Patient table. Choose from the database menu Tools relationships (version2 of Access: Edit relationships). Or click the appropriate speed button on the toolbar. You should now have a 'Show table' dialogue box in front of you. If you do not Choose the menu option Relationships Show table (version2 of Access: Relationships -> add table) Another dialogue box appears requesting which table(s) you would like to add. Within the Show table dialogue box (displayed opposite): Choose 'doctor' by highlighting it then click the add button. Choose 'patient' by highlighting it then click the add button. Click the close button. You should now have the two tables you chose above in the relationship window. You can resize the various tables to see all the fields by dragging the sides of the tables. You can also move the tables in the window until they're arranged in the layout you want. The next stage is to create the relationship between the two tables: To create a relationship, you use the mouse to drag one or more fields from the master table to the child table. To drag multiple fields, first hold down the Ctrl key and select the fields. When creating a relationship, you drag from the primary key of one table (shown in bold in the field list) to a matching field (the foreign key) in the related table. Creating links Click on the Doc id field of the doctor table and drag to the Doc id field of the patient table (shown in the diagram below). Do not worry about the cursor changing shape when you do this it is supposed to!: Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 5

The relationships dialogue box' now pops up: Enforcing Referential Integrity Click the 'Enforce Referential Integrity' option, as displayed above. Important: This is the option that ensures the values between the key and the foreign key are the same. Click the 'create' button. If you have a error message now such as "unable to create relationship as records unsuitable " You must have forgotten to delete the records in the tables as requested to do so at the beginning of this session. I this is the case Delete them now! Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 6

You should end up with something like the picture below: Key point: Always drag from the primary key to the foreign key. If you don't you'll get the relationship the wrong way round! Add the Episode table to the relationships window. Add the relationship between patient and episode Add the relationship between doctor and episode You will have noticed by now that it is often necessary to move the various tables around to get something that is acceptable visually. Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 7

Now add the last three, diagnosis, tables, to the relationships window. Add the necessary relationships to obtain something similar to the diagram below. 5.1 Saving relationships To save the work you have done above. While in the 'relationships window' choose menu option File Save. (Save layout in Access2) It should be noted that saving while in the relationships window also saves the actual referential integrity rules as well as the layout picture in the relationships window. Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 8

6. What adding Referential Integrity does when entering data The following exercise demonstrates some of the advantages (and disadvantages) of creating relationships and referential integrity constraint. Invalid foreign key value Add the following record to the patient table. Remember to add a record to the database and not just the screen you need to move to another record (row) in the table to give the computer the necessary kick. Field Name Value to add: ID 1 Title First Name Surname Mr john smith Doc ID 23 DOB 01/01/68 What happens. Do you consider this useful? Add your comments: You should have had an error box popping up with the message 'Can't add or change record. Referential integrity rules require a related record in table doctor'. Click the 'OK' button. Delete the record To solve the problem we need to add a doctor record with the required ID: Add a record to the doctor table with an ID of 23. You can put anything you want into the other fields. Remember to add a record to the database and not just the screen you need to move to another record (row) in the table. Then go back to the patient table and try again putting the record in. Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 9

Editing a primary key that is referenced as a foreign key somewhere else. You should now have a record in the doctor table with a ID of 23 and a record in the patients table with a Doctor ID value of 23. The value of the other fields do not matter for now. Try changing the doctor ID value in the doctor table record to 100. What happens? Describe below: Press the 'Esc' key to reset the value to 23. This will undo the editing you have done and allow you to get out of the field Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 10

Deleting a primary key that is referenced as a foreign key somewhere else. You should now have a record in the doctor table with a ID of 23 and a record in the patients table with a Doctor ID value of 23. The value of the other fields do not matter for now. Try deleting the record in the doctor table. What happens? Describe below: If necessary, press the 'Esc' key to reset the record. Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 11

7. An introduction to dependency Introduction to Health Informatics What is happening in the above exercises is all to do with dependency. One table is said to be dependent upon another. The terms parent (or master)' and 'child' are often used. The best way to think about dependency is to consider actions over time using the CRUD matrix discussed in Database Concepts (1)' Concepts (1). Process: Time First action Second action Creation Master Child Updating master: Updating child: Master Master Child updated Child updated only if value is in master field Deleting a master: Deleting a child: Master only if no children exist No problem The above diagram is explained below: Creation of a record: with a foreign key value requires that the value already exists in the table in which the foreign key is the primary key (doctor ID in doctor table must exist before creating a patient record with the doctor ID). Which table would be considered to be the 'master' and the child in the paragraph above? Updating of a master table key field: (the one which does not have the foreign key) This is not allowed. But there are ways around it, try the exercise below. Take a look at the options on the 'relationships' dialogue box (it has been printed out a few pages back). What do you think the cascade options do? Updating a child table record:(i.e. a record in the patient table if it were not related to the episode table). This is not a problem unless you try to change the foreign key value to one that does not exist in the master table. Deleting of a master table key field: (i.e. where the Key is used as a foreign key somewhere else), as we discovered in the exercise above this situation creates problems. The previous exercise should have provided a hint as to how this is partially resolved in Access97. Deleting a child table record: (i.e. a record in the patient table if it were not related to the episode table). This is not a problem. Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 12

Look up the help in Access on relationships. 8. Summary During this session we have seen how Access97 creates and maintains relationships using the Relationships window and the consultations database (cons1). We have also seen the possible problems that can occur if the table structure (i.e. the model) is not thought through, particularly with regard to dependency and updating / deleting records. The added complexity of defining relationships in the model and specifying them in Access97 is unavoidable as they maintain the referential integrity (i.e. synchronisation of all the references = relations) of the database. This was clearly demonstrated in the first exercise where anything could be entered into a foreign key field resulting in parent records related to non-existent doctors (technically called 'dangling pointers')! 9. Check what you have learnt Now go back to the beginning of the material for the session and read through the 'Learning outcomes check list' for it. How many can you tick? If your not sure about any particular one go back through the relevant exercise if you still have a problem then please contact me. Document Info: Robin Beaumont Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Date: 30/03/00 Robin Beaumont 30/03/00 Tel:0191 2731150 e-mail: robin@robinbt2.free-online.co.uk Source: Laptop; C:\HIcourseweb new\chap8\s2\access2.doc Page 13