Sie sind auf Seite 1von 13

Discussion Session 2013.02.

08 by Keehyung Kim UW-Madison Business School

Main parts
Create four tables, set data type, and input data
Set Format correctly (percent, currency) Set Input Mask for Phone field Set validation rule for Email field

Extra credit
Add extra validation rules Add extra fields and records

Purpose
Prevent redundant data in database
Use data in more efficient way

Relational Database (a database using relationship)


SID Student Tom Jenny Program B.S PhD Student Tom Tom Jenny Jenny Jenny Jenny Program B.S. B.S. PhD PhD PhD PhD Course Buddhism Database Database Buddhism Chistians Evolution Credits 3 3 3 3 3 3 Instructor Buddha Lazimy Lazimy Buddha Jesus Darwin 1 2

RowID 1 2 3 4 5 6

CID
1 2 3 4

Course
Database Buddhism Chistians Evolution

Credits
3 3 3 3

Instructor
Lazimy Buddha Jesus Darwin

One-to-Many
Most frequently used relationship
The basic relationship in Access One side should have a unique key

One-to-One
Both side should be linked by unique key fields

Many-to-Many
Access does not support direct Many-to-Many relationship

Need to make meta-table for this relationship


For example, tblOrderProduct is meta-table for this relationship

One-to-many

many-to-many One-to-one

Relationship between two fields within one table

Example: spouse relationship among customers


How-to
Add the same table one more time in Relationships window Link two tables (the same table) Go to Edit Relationship to see correct relationship type

In one-to-many relationship, - Parent table: tblCustomer (one-side)

- Child table: tblOrder (many-side)

A Foreign Key is a field in a relational table that matches

a candidate key of another table.

The foreign key can be used to cross-reference tables.


Source: http://en.wikipedia.org/wiki/Foreign_key

Example
In previous slide, CID in tblOrder is Foreign Key.

Give powerful limitation on editing

data to keep database consistent

Limitation given by Access


Cannot add a child record with a non-existing parent record Cannot delete a parent record if it has child records Cannot change a FK in child record if the FK does not have a match in parent table Cannot change a PK in parent record if linked with child records

Cascade update
When you change a PK in parent record,
all linked FKs in child records will be changed, too

Cascade delete
When you delete a parent record, all linked child records will be deleted, too

Results
Keep consistency of database

But, be extremely careful! The data can be all gone by one click!

Do not use Cascade option on your project!

Due date: before 9:55 am on Feb. 15

Main problems
Create relationships in Access Understand the concept of PK and FK Create Self One-to-one relationship (Extra credit)

Submission
Your Access database file (.accdb) Text file answering the five questions (.txt)

Electronically submit into Discussion Homework 2 dropbox

Related readings: Chapter 5

Das könnte Ihnen auch gefallen