+ All Categories
Home > Documents > Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the...

Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the...

Date post: 11-Jan-2016
Category:
Upload: cassandra-skinner
View: 216 times
Download: 0 times
Share this document with a friend
Popular Tags:
42
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational Databases and Multi-Table Queries Robert Grauer, Keith Mulbery, Maurie Wigman Lockley Exploring Microsoft Office Access 2007
Transcript
Page 1: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall11

Committed to Shaping the Next Generation of IT Experts.

Chapter 2:Relational Databases and

Multi-Table QueriesRobert Grauer, Keith Mulbery, Maurie Wigman Lockley

Exploring Microsoft Office Access 2007

Page 2: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall2

Objectives Design data Create tables Understand table relationships Share data with Excel Establish table relationships Create a query Specify criteria for different data types Copy and run a query Use the Query Wizard Understand large database differences

Page 3: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall3

Table Design Considerations

Just as you first create a blueprint to build a house, you should first sketch or outline the design of a database table

Careful pre-planning

will save you much time

in the future

Page 4: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall4

Table Design Considerations – Field Size Property

Set the field size in Table Design View Always anticipate the current field size may

one day need to be larger

Set field size in the Field Properties grid of Table Design View

Page 5: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall5

Table Design Considerations – Validation Rules

Used to avoid data entry errors by restricting what can be entered

Validation text can be used to provide an explanation of the type of data that is allowed in a field

Set validation rules in the Field Properties grid of Table Design View

Page 6: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall6

Table Design Consideration – Sarbanes Oxley Act (SOX) Protects the general public and companies

shareholders against fraudulent practices and accounting errors. Requires that all business records be saved for a

period of five years and be made available to the SEC upon request

SOX RECORDS

Do Not

Discard

Page 7: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall7

Table Design Considerations - PNPI

Short for personal, non-public, information PNPI laws govern the safeguarding of data such as:

social security numbers credit card numbers bank account numbers medical records

Page 8: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall8

Table Design Considerations – Store Data in its Smallest part

For greater flexibility, store data in its smallest part Instead of one field for an address, use many Instead of one field for a name, two or three

Like this

Not like this

Page 9: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall9

Table Design Considerations – Avoid Calculated Data in a Table

Calculated fields should be used mainly in queries and reports

Calculated fields in a query

Calculated field in a report

Page 10: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall10

Table Design Consideration - Plan for Date Arithmetic

Using a data type of date/time for all date fields allows the use of date arithmetic

Fields declared as a data type of Date/Time

Page 11: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall11

Table Design Considerations – Design Multiple Tables

Using multiple tables helps reduce redundancy The process is also referred to as normalization

Multiple table tabs identify open tables

Multiple tables shown in the Navigation Pane

Page 12: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall12

Creating Tables – From the Create Tab

Enter table data directly in fields From the Create Tab, click Table

Use a table template From the Create Tab, click Table

Templates

Enter data directly into a table, including the field names

Enter field names, data types and descriptions in Table Design View

Begin with a template

Page 13: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall13

Creating Tables – From the Import Tab

Click the application from which to import or Choose the type of file you wish to import

Click the appropriate application button

Choose a file type to import

Page 14: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall14

Create Tables – Specifying field names

After choosing your method of creation begin implementing the table design Use CamelCase notation for field names Specify data types Establish a primary key Consider the need for a foreign key

Table View

Table Design View

Add field in Table View

Page 15: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall15

Create Tables – Primary Key

Tables are automatically created with an AutoNumber field which serves as the primary key

To change the primary key Select a field in Design View Click the primary key icon

Primary Key FieldPrimary Key icon

Page 16: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall16

Create Tables – Consider a Foreign Key

Customer ID - Primary Key in Customer TableCustomer ID –will only appear in one record - there must only be one unique ID per customer

Customer ID - Regular Field in Orders TableCustomer ID may appear many times – one customer can place many orders

Based on the above example: Customer ID is the foreign key in the Orders table This is referred to as a One to Many Relationship

Page 17: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall17

Work with Table Views

Click the Home tab Click View from the ribbon

Table View Options

Page 18: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall18

Work with Properties

Field Properties can be used to specify characteristics for individual fields

Located in the lower pane of Table Design View

Caption property

Field Size property

Page 19: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall19

Working with Multiple Tables – Table Relationships

The strength of Access is the fact that it is a relational database This means you can have multiple tables and

create relationships between each table This helps eliminate redundant data

Relationship between two tables

Page 20: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall20

Working with Multiple Tables – Referential Integrity

Assures that the references to relationships between data is accurate

Established when creating the relationship between two tables

Enforce Referential Integrity

Page 21: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall21

Working with Multiple tables - Cascades

When active, data changed in one table that is in a relationship will be changed in its related tables

Can be set when establishing relationships between tables

C

Cascade update and cascade delete

Page 22: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall22

Indexing

Index properties can be set in the Field Properties pane of table Design View

Relates the field values to the records that contain the field value

Helps speed up some sorting and searching processes

Indexed Property

Page 23: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall23

Sharing Data with Excel

Data can be imported from Excel It may be appended to an existing table It may be used to create a new table

Excel icon

External Data tab

Page 24: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall24

Sharing Data with Excel

Select the Excel file you would like to import Select how you would like to import the data

Appended – added to the end of an existing table New table – creates a new table in a database Linked – create a new table that is linked to the source file

in Excel

Select the Source

Select the destination

Page 25: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall25

Establishing Relationships

Click the Database tools and click the Relationships icon

In the Relationship window, click and drag a field name from one table to a field name in a related table

Relationships iconClick and drag to create a relationship

Page 26: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall26

Establishing Relationships

Enter the appropriate settings in the Edit relationships dialog box and click Create

A join line will appear when one table is joined to another

Infinity symbol notes referential integrity has been applied

Set referential integrity and cascades

Page 27: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall27

Queries

Queries allow us to ask questions about data A record set that answers our question is called a

dataset

Employees table

Dataset resulting from querying table for only employees who are Sales Representatives

Page 28: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall28

Using Query Design View

Query Design grid has two panes – the table pane and the design pane

Striking the F6 key will toggle you between sections

Tables pane

Design pane

Page 29: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall29

Select Query

Searches associated tables and returns a dataset that matches the query parameters

Changes made to the dataset will be reflected in the associated tables

Page 30: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall30

Specifying Criteria in a Select Query

Table row – displays the data source. Field row – displays the field name Sort row – enables you to sort the dataset Show row – controls whether or not you see a field

in the dataset Criteria row – determines the records that will be

selected for display

Fields in design grid allow us to specify criteria for the dataset

Page 31: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall31

Specifying Criteria – Currency and Operands

Specify criteria with currency Without the dollar sign With or without the decimal point

Use operands such as: Less than and greater than Equal to or not equal to

Greater than (>) operand

Currency amount entered without dollar sign

Page 32: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall32

Specifying Criteria – Wildcards

Asterisk - searches for a pattern that includes any number of characters in the position of the asterisk

Question mark - searches for a pattern that includes a single character in the position of the question mark

Query with question mark and asterisk wildcard and resulting dataset to specify criteria for the dataset

Query with asterisk wildcard and resulting dataset

Page 33: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall33

Specifying Criteria – Null Values

IS NULL finds only records that have no value IS NOT NULL excludes Null value records

Is Null criteria and resulting dataset

IS NOT NULL criteria and partial resulting dataset

Page 34: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall34

Specifying Criteria – AND, OR, NOT

OR finds records that can match one or more conditions

AND finds records that must match all criteria specified NOT returns the opposite of the specified criteria.

Or Criterion and resulting dataset

And criterion and resulting dataset

Page 35: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall35

Copy a Query

Right click on the query - chose Copy form the shortcut menu

Right click and chose paste In the Paste as dialog box, give the query a

new name

Page 36: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall36

Run a Query

Running or executing a query is done by clicking the Run command

Run command

Page 37: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall37

Creating Queries – Using the Query Wizard

From the Create tab, choose Query Wizard for the Other group

Choose query type from the New Query dialog box

Query Wizard icon

Select Simple Query Wizard

Page 38: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall38

Creating Queries – Using the Query Wizard: continued

Select the Table/Queries to include and choose the desired fields

Select aggregate totals needed in the Summary Options box

Page 39: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall39

Creating Queries – Using the Query Wizard: continued

Title your query and open in Datasheet View or Query Design View

Page 40: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall40

Understand Large Database Differences Most large companies separate their

database into front and back ends Front end – contains the objects needed to

interact with data, but not the tables where the record values reside

Back end – contains the tables where the data resides

Page 41: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall41

Questions?

Page 42: Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.

Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice Hall42

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic,

mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America.

Copyright © 2010 Pearson Education, Inc.  Copyright © 2010 Pearson Education, Inc.  Publishing as Prentice HallPublishing as Prentice Hall


Recommended