access chapter 2: relational database objectives design data create tables understand table...

32
Access Chapter 2: Relational Database Objectives • Design data • Create tables • Understand table relationships • Understand data types, key, & field properties • Establish table relationships • Create a single-table query • Specify criteria for different data types 1

Upload: grace-lane

Post on 20-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Access Chapter 2: Relational Database Objectives

• Design data• Create tables• Understand table relationships• Understand data types, key, & field

properties• Establish table relationships• Create a single-table query• Specify criteria for different data types

1

Page 2: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Table Design: Designing Data

• Table Definition – Revised• Input vs. Output in Design

2

Page 3: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Designing Fields Guidelines

1. Include the necessary data2. Design for now and the future3. Store data in its smallest parts4. Add calculated fields to a table5. Design to accommodate date

arithmetic6. Link tables using common fields

3

Page 4: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Include Necessary Data

• Determine what data is necessary• Create a rough draft of reports that

may be needed• Create tables based on fields

necessary for reports

4

Page 5: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Design for Now and the Future

• Organizations evolve over time• Databases should evolve with the

organization– Anticipate future needs of the

organization– Build flexibility into system to satisfy

future needs

5

Page 6: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Store Data in Smallest Possible Pieces

• Creating a name field with the entire name in it violates good database design and reduces the usefulness of the data

• Divide data into the smallest pieces that you’re going to need to access– Example: Prefix, FirstName, LastName,

Suffix

• Provide flexibility for the user6

Page 7: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Calculated Fields in a Table

• Produce a value from an expression or function that references one or more existing fields

• Access 2010 allows the user to store calculated fields– Can be a benefit or a potential problem– Exercise caution when using calculated

(derived) fields

7

Page 8: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Design to Accommodate Date Arithmetic

• Calculated fields can also create date/time data

• Plenty of examples available for using date/time date arithmetic

8

Page 9: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Link Tables Using Common Fields

• Tables may be joined based on a common field

• Join lines are created –Manually by the user, or – Automatically by Access when two

fields in separate tables share the same name between two related tables

• Avoid Data redundancy errors– The unnecessary storage of duplicate

data in two or more tables9

Page 10: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Creating Tables

• Create fields in Design View• Import data from another database

or application– Examples: Excel spreadsheets or Word

text files

• Enter data directly into rows in Datasheet view

10

Page 11: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Creating Fields in Tables

• Field names should be meaningful• Rules for naming fields:– Length can be up to 64 characters– Can include letters, numbers and

spaces– Access uses CamelCase notation• Use uppercase letters for each first letter of

each new word• Example: ProductCost

11

Page 12: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Field Data Types

• Every field has a data type • Determines:– The type of data that can be entered – The operations that can be performed

on that data

• Access recognizes 10 data types

12

Page 13: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Access Data Types

• Number• Text• Memo• Date/Time• Currency• Yes/No

• OLE• AutoNumber• Hyperlink• Attachment

13

Page 14: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Foreign Key Review

A field in one table that is also a primary key of another table

14

SpeakerID is the primary key of the Speakers

SpeakerID is the foreign key in the SessionSpeaker table (duplicates are allowed)

Page 15: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Using Table Views

Datasheet View

15

Active record

Page 16: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Using Table Views

• Design View• PivotTable• PivotChart

16

Page 17: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Work with Field Properties

• Field property• Text data type• Number data type• Caption property• Validation rule

17

Page 18: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Access Field Properties

• Field Size• Format• Input Mask• Caption• Default Value• Validation Rule• Validation Text

18

Page 19: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Access Field Properties (continued)

• Required• Allow Zero Length• Indexed• Expression• Result Type

19

Page 20: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Understanding Table Relationships

• Efficiently combine data from related tables

• Create queries, forms, and reports

20

Page 21: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Establishing Referential Integrity

• Edit Relationships dialog box

• Select Enforce Referential Integrity checkbox

21

Page 22: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Set Cascade Options

• Cascade Update Related Fields• Cascade Delete Related Records

22

Click Cascade Delete with caution

Click Cascade Update incase the primary key changes

Click Enforce Referential Integrity

Page 23: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Indexing to Retrieve Data Quickly

• Provides quick sorting based on the primary key

• Provides quick retrieval of data based on the primary key

23

Page 24: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Options on External Data Tab

• Import & Link• Export• Collect Data• Web Linked Lists

24

External Data TabClick Excel to importspreadsheet data

Page 25: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Import Data from Excel

25

Click Browse to finda spreadsheet

Decide what you wantto do with the data

Page 26: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Import Data from Excel (continued)

26

Choose the worksheetto import

Preview of theworksheet data

Click Next to continue

Page 27: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Types of Relationships

• One-to-one relationship• One-to-many relationship• Many-to-many relationship

27

Page 28: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Establishing a One-to-Many Relationship

• Open Relationships window• Add tables• Establish

relationships

28

Show Table window

Page 29: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Relationships Between Tables

29

Edit Relationshipsdialog box

One-to-many relationships

Page 30: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Relationships Window

30

Join lines

1 side

Many side:the “” (infinity symbol)

Page 31: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Single-Table Queries

• Show Table• Design Grid to

add– Field row– Table row– Sort row– Show row– Criteria

31

Query Design Grid—Fields, Sorting, and Criteria

Query Design—Tables

Page 32: Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties

Datasheet View of Results

32

Query results inDatasheet view

Only accounts with abalance over $5,000

Nine records matchthe criteria