Access07_L1_Ch2

download Access07_L1_Ch2

of 27

Transcript of Access07_L1_Ch2

  • 8/6/2019 Access07_L1_Ch2

    1/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-1

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    CREATING RELATIONSHIPSBETWEEN DATABASE TABLES

    Microsoft Access 2007 Microsoft Access 2007 Level 1 Level 1

  • 8/6/2019 Access07_L1_Ch2

    2/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-2

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    P erformance ObjectivesP erformance Objectives

    Create a database table with aprimary keyCreate a database table with a

    foreign keyCreate a relationship betweendatabase tablesP rint table relationshipsDisplay Subdatasheets

  • 8/6/2019 Access07_L1_Ch2

    3/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-3

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating Related TablesCreating Related Tables

    Access is a relational databasemanagement system

    Relationships are defined between sets

    of data (tables) allows greater flexibility in manipulating

    data eliminates redundancy

  • 8/6/2019 Access07_L1_Ch2

    4/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-4

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Determining RelationshipsDetermining Relationships

    P lanning is most importantBreak down fields into tables to avoid redundancies

    Clients tableClient #ClientStreet AddressCityStateZip Code

    Insurance tableLicense #Client #Insurance CodeUninsured Motorist

    Coverage tableInsurance CodeType of Insurance

    Claims tableClaim #Client #License #Date of ClaimAmount of Claim

    N otice that eachtable is about

    only one subject

    Some fields appear in more than onetable they are used

    to createa relationship

  • 8/6/2019 Access07_L1_Ch2

    5/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-5

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating a P rimary FieldCreating a P rimary Field

    Need to designate a primary (key) fieldin a table before creating a relationshipbetween tables

    Must contain unique dataAccess enforces Entity Integrity

    expects a value in the primary field in

    each record cannot close a table containing a null

    value in a primary (key) field

  • 8/6/2019 Access07_L1_Ch2

    6/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-6

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating a P rimary Field/2Creating a P rimary Field/2

    Open table in Design view

    Positioninsertionpoint in

    field

    Click PrimaryKey button

    N otice image

    of key

    To define more than one field as the primary key,select the rows and click the Primary Key button

  • 8/6/2019 Access07_L1_Ch2

    7/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-7

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating a Foreign KeyCreating a Foreign Key

    A primary key field in one tablemay be a foreign key in another

    P rimary key and foreign key form

    a relationship

    between the tables

    Clients tableClient #

    ClientStreet AddressCityStateZip Code

    Insurance tableLicense #Client #Insurance CodeUninsured Motorist

    Coverage tableInsurance CodeType of Insurance

    Claims tableClaim #Client #License #Date of ClaimAmount of Claim

  • 8/6/2019 Access07_L1_Ch2

    8/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-8

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Establishing a RelationshipEstablishing a Relationship

    Relate one table to another by join ingthe tables

    data can be extracted from both tables

    Define the type of relationship to becreated one record in the primary table will match

    zero, one, or many records in the related

    table ( one-to-one, or one-to-many)Set Referential Integrity

    a record must be added to the one tablebefore it can be added to the many table

  • 8/6/2019 Access07_L1_Ch2

    9/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-9

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating a OneCreating a One- -toto--Many RelationshipMany Relationship

    Open database file

    Click Database Toolstab, Relationships

    Show Table dialog box

    appears when norelationships have beendefined yet

  • 8/6/2019 Access07_L1_Ch2

    10/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-10

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating a OneCreating a One- -toto--Many Relationship/2Many Relationship/2

    Double-click eachtable to add it to the

    Relationships window After addingall the tables

    Repeat until all requiredtables are added

    Click Closewhen done adding

    Notice that thePrimary keysare indicated

  • 8/6/2019 Access07_L1_Ch2

    11/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-11

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating a OneCreating a One- -toto--Many Relationship/3Many Relationship/3

    Drag the common field from the primary table(the one ) to the related table (the many )Edit Relationshipsdialog box appears

    Ensure that the correcttables and field names

    display

    Make sure type isOne- To-Many

    Click

    Check optionsas desired

  • 8/6/2019 Access07_L1_Ch2

    12/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-12

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating a OneCreating a One- -toto--Many Relationship/4Many Relationship/4

    J oin line is thick at both ends if referential integrityoption has been chosen

    Save theRelationship

    by clicking theSave buttonin the Quick

    Access toolbar

    J oin line

    This join line shows that each client mayhave many claims (1 to )

  • 8/6/2019 Access07_L1_Ch2

    13/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-13

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Specifying Referential IntegritySpecifying Referential Integrity

    If a related tablecontains a record, you

    will not be able tochange or delete

    a primary key value inthe primary table

    As you changea primary key value in the

    primary table, Accesswill automatically updatethe matching value in the

    related tables

    As you delete a recordin the primary table,

    Access will also deleteany related records in

    the related tables

  • 8/6/2019 Access07_L1_Ch2

    14/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-14

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    P rinting Database RelationshipsP rinting Database Relationships

    W ith the Relationships open, click theRelationship Report button

    T he Relationships report in P rint P review

    Click the Print button in Quick Access toolbar

  • 8/6/2019 Access07_L1_Ch2

    15/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-15

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Creating Additional RelationshipsCreating Additional Relationships

    Open Relationships if necessaryand click the Show Table buttonto add other tables to thedatabase relationships

    Drag a primary key in one table toa foreign key in another table

    Follow the same procedure as before to

    verify the table fields andthe relationship type,and to set the

    desired referential integrity

  • 8/6/2019 Access07_L1_Ch2

    16/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-16

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Editing a RelationshipEditing a Relationship

    Right-click a join lineand click

    Edit RelationshipOR OR

    Can move a table entryby dragging its Title bar

    Open Relationships

    Click a joinline andclick

    OR OR Double-click

    a join line

  • 8/6/2019 Access07_L1_Ch2

    17/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-17

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    DeletingDeleting a Relationshipa Relationship

    Open Relationships

    Right-click a join lineand click Delete

    OR OR Click a joinline and pressthe Delete key

  • 8/6/2019 Access07_L1_Ch2

    18/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-18

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    ShowingShowing a a SubdatasheetSubdatasheet

    Click + signpreceding

    desired record+ expands- collapses

    Select tableClick OK

  • 8/6/2019 Access07_L1_Ch2

    19/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-19

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Displaying Related Records in a SubdatasheetDisplaying Related Records in a Subdatasheet

    Can view, edit or add data in th e sub datash ee t

    C lick + si g n prece din g

    d e sir e d r eco rd + exp ands - coll a p s e s

    On ly a v ai la ble w h e n ta ble s ha ve r el ationshi p s

  • 8/6/2019 Access07_L1_Ch2

    20/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-20

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Managing SubdatasheetsManaging Subdatasheets

    Can choos e a

    di ff e r e nt su b datash ee t

    With an o pe n ta ble C lic k H o me ta b, M or e b utton

    ( in th e Re cords g rou p)

    Can r em o veth e

    su b datash ee t

    S a me as c lic k ing th e + or p r e c e ding e ach r e cord o f th e ta ble

  • 8/6/2019 Access07_L1_Ch2

    21/27

  • 8/6/2019 Access07_L1_Ch2

    22/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-22

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    H ow do you display the Relationshipswindow?

    Database Tools tab,

    Relationshipsbutton

    Features Summary

  • 8/6/2019 Access07_L1_Ch2

    23/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-23

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign KeysRelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    H ow do you display the Edit Relationshipsdialog box?

    Features Summary

    Right-click a join lineand click

    Edit Relationship

    OR OR Click a joinline andclick

    OR OR Double-clicka join line

  • 8/6/2019 Access07_L1_Ch2

    24/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-24

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign Keys

    RelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    H ow do you display the Show T abledialog box?

    Database Tools tab, Relationships,click the Show Table button

    Features Summary

  • 8/6/2019 Access07_L1_Ch2

    25/27

  • 8/6/2019 Access07_L1_Ch2

    26/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-26

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign Keys

    RelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    H ow do you display the Insert Subdatasheet dialog box?

    Features SummaryFeatures Summary

    Click the + signpreceding a record

    Click Home tab,Records group,

    More button,Click

    Open a tableOR

    Features Summary

  • 8/6/2019 Access07_L1_Ch2

    27/27

    Copyright 2007, Paradigm Publishing Inc.

    ACCESS 2007Chapter 2

    BACK NEXT END

    2-27

    LINKS TO OBJECTIVES Creating RelatedTablesDeterminingRelationshipsPrimary KeysForeign Keys

    RelationshipsReferential IntegrityPrintingRelationshipsSubdatasheetsFeatures Summary

    Coming NextComing Next

    M ODIFYING AND M ANAGING

    TABLES