Upload
elizabeth-de-leon-aler
View
1.565
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-1
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
CREATING RELATIONSHIPS BETWEEN DATABASE TABLES
Chapter 2Chapter 2
Microsoft Access 2007 – Level 1Microsoft Access 2007 – Level 1
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-2
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Performance ObjectivesPerformance Objectives
• Create a database table with a primary key
• Create a database table with a foreign key
• Create a relationship between database tables
• Print table relationships• Display Subdatasheets
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-3
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating Related TablesCreating Related Tables
• Access is a relational database management system
• Relationships are defined between sets of data (tables)– allows greater flexibility in manipulating
data– eliminates redundancy
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-4
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Determining RelationshipsDetermining Relationships
Planning is most important Break 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
Notice that eachtable is about
only one subject
Some fields appearin more than one
table – they are used to create
a relationship
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-5
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating a Primary FieldCreating a Primary Field
• Need to designate a primary (key) field in a table before creating a relationship between tables
• Must contain unique data
• Access 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
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-6
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating a Primary Field…/2Creating a Primary Field…/2
Open table in Design view
Position insertio
npoint in
field
Click Primary Key button
Notice image of key
To define more than one field as the primary key, select the rows and click the Primary
Key button
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-7
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating a Foreign KeyCreating a Foreign Key
A primary key field in one tablemay be a foreign key in another
Primary key and foreign key form
a relationshipbetween 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
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-8
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Establishing a RelationshipEstablishing a Relationship
• Relate one table to another by joining the tables– data can be extracted from both tables
• Define the type of relationship to be created– 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” table
before it can be added to the “many” table
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-9
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating a One-to-Many RelationshipCreating a One-to-Many Relationship
Open database file
Click Database Tools tab,
Relationships
Show Table dialog box appears when no
relationships have been defined yet
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-10
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating a One-to-Many Relationship…/2Creating a One-to-Many Relationship…/2
Double-click each table to add it to the Relationships
window
After adding all the tables
Repeat until all required tables are
added
Click Closewhen done adding
Notice that the Primary keys are indicated
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-11
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating a One-to-Many Relationship…/3Creating a One-to-Many 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
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-12
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating a One-to-Many Relationship…/4Creating a One-to-Many Relationship…/4
Join line is thick at both ends if referential integrity option has been chosen
Save theRelationshipby clicking the Save button
in the Quick Access toolbar
Join line
This join line shows that each client may have many claims (1 to ∞)
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-13
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Specifying Referential IntegritySpecifying Referential Integrity
If a related table contains a record,
you will not be able to change or deletea primary key value
inthe primary table
As you change a primary key value in the
primary table, Accesswill automatically updatethe matching value in the
related tables
As you delete a record
in the primary table, Access will also
delete any related records in the related
tables
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-14
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Printing Database RelationshipsPrinting Database Relationships
With the Relationships open, click the Relationship Report button
The Relationships report in Print Preview
Click the Print button in Quick Access toolbar
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-15
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Creating Additional RelationshipsCreating Additional Relationships
Open Relationships if necessary and click the Show Table button to add other tables to the database relationships
Drag a primary key in one table to a foreign key in another table
Follow the same procedure as before to verify the table fields and
the relationship type, and to set the
desired referential integrity
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-16
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Editing a RelationshipEditing a Relationship
Right-click a join lineand click
Edit RelationshipOROR
Can move a table entry by dragging its Title bar
Open Relationships …
Click a join line and click
ORORDouble-
click a join line
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-17
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Deleting a RelationshipDeleting a Relationship
Open Relationships …
Right-click a join lineand click Delete
ORORClick a join line and press the Delete key
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-18
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Showing a SubdatasheetShowing a Subdatasheet
Click + signpreceding
desired record+ expands- collapses
Select tableClick OK
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-19
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Displaying Related Records in a SubdatasheetDisplaying Related Records in a Subdatasheet
Can view, edit or add data in the
subdatasheet
Click + signpreceding
desired record+ expands- collapses
Only available when tables have relationships
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-20
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Managing SubdatasheetsManaging Subdatasheets
Can choose a different
subdatasheet
With an open table …Click Home tab, More button
(in the Records group)
Can remove the
subdatasheet
Same as clicking the + or – preceding each record of the
table
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-21
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
How do you identify a primary key?
Features Summary
Image of a key shows by the field name
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-22
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
How do you display the Relationships window?
Database Tools tab,Relationshipsbutton
Features Summary
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-23
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
How do you display the Edit Relationships dialog box?
Features Summary
Right-click a join lineand click
Edit RelationshipORORClick a
join line and click
OROR Double-click a join
line
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-24
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
How do you display the Show Table dialog box?
Database Tools tab, Relationships,click the Show Table button
Features Summary
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-25
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
How do you print database relationships?
With the Relationships open, click the Relationship Report button
Click the Print button in Quick Access toolbar
Features Summary
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-26
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
How 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
Copyright 2007, Paradigm Publishing Inc.
ACCESS 2007Chapter 2
BACK NEXT END
2-27
LINKS TO
OBJECTIVES
• Creating Related Tables
• Determining Relationships
• Primary Keys• Foreign Keys• Relationships• Referential
Integrity• Printing
Relationships• Subdatasheets• Features
Summary
Coming NextComing Next
MODIFYING AND MANAGING TABLES
Chapter 3Chapter 3