38
Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Embed Size (px)

Citation preview

Page 1: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Microsoft Access Lesson 3

Lexington Technology Center

February 18, 2003

Bob Herring

On the Web at www.lexington1.net/AdultEd/computer/microsoft_access.htm

Page 2: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Review of Thursday’s Lesson

• Template Databases• Database Wizard• Switchboard Forms• Forms and Controls• Reports• Database Window

2

Page 3: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Relationships

• Tables can be related if they have a field in common. Access uses the relationship to create information by matching the fields and reporting the results.

• There are 3 types of relationships:

• One-to-many: Each record in the primary table can be associated with many records in the related table

• One-to-one: Each record in the primary table can be associated with only one record in the related table

• Many-to-many: More than one record in the primary table can be associated with many records in the related table 3

Page 4: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Relationships in Access

• The table on the “one” side of the relationship is called the parent table. The other table is called the child table.

• How the 3 types of relationships are created in Access:

• One-to-many: The common field in the parent table is called the primary key, and the related field in the child table is called the foreign key.

• One-to-one: The common fields are both primary keys.

• Many-to-many: Ordinarily not possible, but in Access two one-to- many relationships can be joined to create this kind of relationship.

4

Page 5: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3One-to-Many Relationships

ParentTable

PrimaryKey

ForeignKey

ChildTable

Relationship Line

• In this example, one category can encompass many products

5

Page 6: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3One-to-One Relationships

• These two tables have a one-to-one relationship because they concern the same subject: employees

6

Page 7: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Many-to-Many Relationships

JunctionTable

• Since many orders might call for many products, a junction table is used to avoid violating referential integrity.

7

Page 8: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Referential Integrity

• Optional series of rules that guarantees that relationships will be valid.

• Every record in a child table (the “many” side) must have one and only one record in the parent table (the “one” side)

• No child record can be entered without a parent• No parent record can be deleted if it still has children• No child record’s foreign key can be changed without a match in the parent table• No parent table’s primary key can be changed if there are child records

8

Page 9: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Referential Integrity, Continued

ReferentialIntegrityEnforced

• What you need to enforce referential integrity in Access:• The matching field in the parent table must be the primary key• Relating fields must be the same data type• Both tables must be in the same database -- OR, if using linking fields, both tables must be in Access and the linked table’s database must be open

• Referential integrity is indicated by 1 - on the relationship line

9

Page 10: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Referential Integrity, Continued

Edit Relationship

• Referential integrity is set by editing the relationship• Right-click the relationship line and select Edit Relationship • Click the “Enforce Referential Integrity” check box

Enforce Referential Integrity

10

Page 11: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Referential Integrity, Continued

Cascade Delete

• If referential integrity is selected, you can also choose to have Access automatically update or delete records• Cascade Update and Cascade Delete maintain referential integrity by changing child tables to match changes in the parent table

• Beware of Cascade Delete!! This could lead to loss of data!• Cascade Update has no effect if you are using a primary key since you cannot change an autonumber

Cascade Update

11

Page 12: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Joins

InnerJoin

RightOuter Join

LeftOuter Join

Left Right

• A join is a control that tells Access which records to select when running a query.• Inner joins are the most common.• Outer joins include all records from one of the tables and records from the other when the joined fields match.

12

Page 13: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Address Book Relationships

13

Page 14: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Asset Tracking Relationships

14

Page 15: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Contact Management Relationships

15

Page 16: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Event Management Relationships

16

Page 17: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Expenses Relationships

17

Page 18: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Students and Classes Relationships

18

Page 19: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Inventory Control Relationships

19

Page 20: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Ledger Relationships

20

Page 21: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Resource Scheduling Relationships

21

Page 22: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Time and Billing Relationships

22

Page 23: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Membership Relationships

23

Page 24: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Order Entry Relationships

24

Page 25: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Book Collection Relationships

25

Page 26: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Music Collection Relationships

26

Page 27: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Form Wizard

• In the Northwind database, select the “Forms” tab• Click the “New” button

27

Page 28: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Form Wizard

• In the “New Form” dialog box, click “Form Wizard”• Choose the Products table to begin, then click “OK”

28

Page 29: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Wizard, Step 2 -- Data Fields

• Step 2 is to choose fields from the available tables and queries• Click the right arrow to select the desired fields, or• Click the double right arrow to select all

29

Page 30: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Choosing Fields for a Form

• Select “ProductName”, “SupplierID”, “UnitsinStock”, and “Discontinued”• Choose “Next”

30

Page 31: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Wizard, Step 3 -- Layout Style

• In Step 3, select a layout style for the form• Click through the four choices to preview the different styles• Click “Next”

Columnar Tabular

31

Page 32: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Wizard, Step 3 -- Layout Style

• In Step 3, select a layout style for the form• Click through the four choices to preview the different styles• Click Next

Datasheet Justified

32

Page 33: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Wizard, Step 4 -- Background Style

• In Step 4, select a background style for the form• Click through the choices to preview the different styles

33

Page 34: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Wizard, Step 5 -- Finish

• To finish the form, give it a name and click “Finish”• Click the radio button to open the form after creating it

Openthe Form

34

Page 35: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Automatic Form in Action

• The new form displays a portion of the information in the table• Forms are two-way -- they display information, but also guide data entry

35

Page 36: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Adding a New Product

• Click the “New Record” button• Notice that the “Supplier” field is lit -- this is referential integrity in action -- every product must have a supplier!

36

Page 37: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Adding a New Product

• After choosing a supplier, enter the name of the new product• Enter the number of units in stock• Data entered in the form is immediately saved in the database

37

Page 38: Microsoft Access Lesson 3 Lexington Technology Center February 18, 2003 Bob Herring On the Web at

Access Lesson 3Review

• Relationships• Referential Integrity• Joins• Template Database Relationships• Automatic Forms

38