1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006...

25
Dec 1 fit100-25-advdatabases © 2006 University of Washington 1 The Information School of the University of Washington Advanced Database Concepts INFO/CSE 100, Fall 2006 Fluency in Information Technology http://courses.washington.edu/info100/

Transcript of 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006...

Page 1: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 1

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton Advanced Database Concepts

INFO/CSE 100, Fall 2006

Fluency in Information Technology

http://courses.washington.edu/info100/

Page 2: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 2

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Readings and References

• Reading» Fluency with Information Technology

• Chapter 16, Case Study in Database Design

• References» MS Access Help files

• keyword “form”

» MS Access Help files• Section “Reports and Report Snapshots”

Page 3: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 3

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Views as Tables

• Recall that the result of a query is a table

• We have been presenting the table to the user in simple tabular form

Page 4: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 4

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

But tables are not pretty …

Users need help understanding what they are looking at and what they can do with it …

… so we developed Forms for controlling the display of data for the user who is reviewing or updating specific records.

Page 5: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 5

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Views as Forms

A form is primarily used to enter or display data in a database

Last lecture we developed Forms for better display to the user while updating the table.

Page 6: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 6

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

But forms are not very compact …

Users like to have reports densely packed with information and logically arranged …

So you can develop Reports for compact display of multiple records.

Page 7: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 7

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

tonReports

• A Report is another face for a table (or query)

• The report lets the designer arrange the data, label it, provide some control over events, etc» the presentation

» multiple presentations are possible depending on the specific needs of each user

• Underlying data comes from a table or a query» the content

» single source of data ensures consistency

Page 8: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Books

Publishers

Authors

ISBN Title

Price

ID Phone

Name

ID Phone

Name

PublisherOf

1

WrittenBy∞ ∞

entity-relationship diagram for Library database

Page 9: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 9

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Creating a table in Design view

Page 10: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 10

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Entering Table Data

Page 11: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 11

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Build another table

Page 12: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 12

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Add publisher ID to booksPK->FK

Page 13: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 13

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Create the link between the tables

Page 14: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 14

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Two tables with a relationship

Page 15: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 15

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Referential Integrity

Page 16: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 16

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Books

Publishers

PublisherOf

1

This relationship is 1-to-many:• One publisher is responsible for many books.• Each book has only one publisher.

What is the relationship?

• The two tables are joined using the publisher ID number.• The publisher ID is the primary key for each entry in the

publishers table.• Therefore, each publisher must have a unique publisher ID.

• The publisher ID is a foreign key for each entry in the books table and we have requested referential integrity

• Therefore, the given publisher ID must exist in the publishers table.

Page 17: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Books

Publishers

Authors

ISBN Title

Price

ID Phone

Name

ID Phone

Name

PublisherOf

1

WrittenBy∞ ∞

Hey presto, we have a database!

Page 18: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 18

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Create a query

Page 19: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 19

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Select particular rows

Page 20: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 20

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

This relationship is many-to-many:• One book may have several authors.• One author may have written several books.

What is the relationship?

• We need a unique identifier for each book.• We already selected the ISBN as the primary key and asked Access to

make sure that there are no duplicates• We need a unique identifier for each author

• We will define an author table with a unique ID for each author

Books Authors

ISBN Title

Price

ID Phone

Name

WrittenBy∞ ∞

Page 21: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 21

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Link one book with many authors?

• We DO want:» to link each book to one or more authors

• We DON'T want» to specify extra fields (author1, author2, author3,

…)• this is wasteful and limits the max number of authors

» to specify each book entry several times, naming a different author in each row• this duplicates all the other information about the book

Page 22: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 22

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Add a cross-reference table!

• Refine the design so that it includes another table that is a book-author cross reference» Each entity in the table is a single cross reference

• Attribute: ISBN

• Attribute: Author ID

» Primary key is combination of both columns

• Now we can break the many-to-many relationship into two 1-to-many relationships that we already know how to implement

Page 23: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 23

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Define new cross-reference entities

Books Authors

ISBN Title

Price

ID Phone

Name

∞ ∞Book/Author

ISBN AuthorID

1 1

Page 24: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 24

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

book-author table

Page 25: 1 The Information School of the University of Washington Dec 1fit100-25-advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.

Dec 1 fit100-25-advdatabases © 2006 University of Washington 25

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Next Week / Extra Credit

• You are an IT Consultant to a Seattle Health Clinic! Help them make use of technology to benefit their clinic.» In class

• Monday: Break into groups to come up with IT solutions for our clinic

• Wednesday: Present to class your groups solutions

» Extra Credit - Design Database Schema, and DB use