Top Banner
Nov 27 fit100-23-databases © 2006 University of Washington 1 The Information School of the University of Washington Database Intro INFO/CSE 100, Fall 2006 Fluency in Information Technology http://courses.washington.edu/info100/
35

1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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 Database Intro

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 Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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 14, Introduction to Database Concepts

• References» Access Database: Design and Programming

• by Steve Roman, published by O'Reilly

Page 3: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Why Study Databases?

• Some of us want to compute, but all of us want information …

• Much of the archived information is in tables

• Databases enhance applications, e.g. Web

• Once you know how to create databases, you can use them to personal advantage

• Databases introduce interesting ideas

Page 4: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Relational Databases

• Information is stored in tables» Tables store information about entities» Entities have characteristics called attributes» Each row in a table represents a single entity

• Each row is a set of attribute values

• Every row must be unique, identified by a key

» Relationships -- associations among the data values are stored

Table structure = schema Table contents = instance

Page 5: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Schema for Example table: ID number unique number(Key) Last text person’s last name First text person’s first name JobCode number current position Hire date first day on job ...

A Table in a Database

Tables have names, attributes {fields}, entities {rows}

instance

schema

Page 6: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Two tables in a database

Page 7: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 7

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Redundancy in a database is Very Bad • Not every assembly of tables is a good database• Repeating data is a bad idea

» Replicated data can differ in its different locations, e.g. multiple addresses can differ• Inconsistent data is worse than no data• Cut down on the typos and mis-keyed entries

» Keep a single copy of any data• Reduces memory and data processing costs• if it is needed in multiple places, associate it with a key and

store key rather than the data

» Effort to update is high

Page 8: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 8

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Relationships between tables

Page 9: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Query to a database (set of tables) produces a new table

“You can look it up”• When looking for information, a single

item might be the answer, but a table is more likely» Which employees live in Kirkland?

• Table of employees

» Who is taking INFO/CSE 100?• Table of students

» Whose mile run time 4:00?• Table of runners

Page 10: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Select Operation

• Select creates a table from the rows of another table meeting a criterion

Select * from Perms Where Hire < 1993

Page 11: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

More Select Operation

• Select creates a table from the columns of another table

Select Last, First From Perms

This is a select from 9 dimensions to 2 dimensions

Page 12: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Union

• Union combines two tables with same attributesSelect * From Perms Union Select * From Temps

Page 13: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Join

• Combines rows if common field matchesSelect * From Perms inner join JobCodes on

Perms.JobID = JobCodes.JobID

Page 14: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

DB Operations

• These various DB Operations can create any table from a given set of tables

• All modern database systems are built on these relational operations

• The operations are not usually used directly, but are used indirectly from other languages

• Structured Query Language (SQL) is the language that we talk to the database in

Page 15: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Database Structure

• A database contains one or more tables» Tables include entities with attributes» There are relationships defined between the entities in

the various tables» Retrieve information from the tables using queries» Create GUI front ends (forms and reports) for users

• First, design the database or create the schema» What are the entities?» What are the attributes of each entity? Are they

atomic?» What are the relationships between tables?

Page 16: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Build a Library Database Schema

• What are the entities?

• What are the attributes of each entity? Are they atomic?

• What are the relationships between tables?

Page 17: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Books

Publishers

Authors

ISBN Title

Price

ID Phone

Name

ID Phone

Name

PublisherOf

1

WrittenBy∞ ∞

entity-relationship diagram for Library database

Page 18: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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 new database

Page 19: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Create a new table in the database

Page 20: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Creating a table in Design view

Page 21: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Entering Table Data

Page 22: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Build another table

Page 23: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Add publisher ID to books

Page 24: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 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

Create the link between the tables

Page 25: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Books

Publishers

Authors

ISBN Title

Price

ID Phone

Name

ID Phone

Name

PublisherOf

1

WrittenBy∞ ∞

Hey presto, we have a database!

Page 26: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 26

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 27: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 27

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Create a query

Page 28: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 28

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

The query produces a new (virtual) table

Page 29: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 29

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Select particular columns

Page 30: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 30

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Select particular rows

Page 31: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 31

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

SQL behind the scenes

Page 32: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 32

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Summary

• Databases : built on tables» Tables represent entities» Tables/Entities have attributes (fields)» Tables have a primary key (unique to that table)

• Related tables are “linked” using primary keys• Structured Query Language (SQL) used to ask

questions of database» SQL typically “called” from other programming

languages» Can limit rows, columns, and join tables

Page 33: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 33

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Questions

• A(n) ______ is a unique identifier for any row in a database table.

• The ______ operation takes rows from a table to create a new table.

Page 34: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 34

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Questions

• For the following, either indicate that the field is atomic or divide the field to make the result atomic.

Field ContentsStudentNo 47385633Phone (206) 555-1212Name Maria MurrayClass INFO100 : ABCity Seattle, WA 98115DOB September 26, 1983

Page 35: 1 The Information School of the University of Washington Nov 27fit100-23-databases © 2006 University of Washington Database Intro INFO/CSE 100, Fall 2006.

Nov 27 fit100-23-databases © 2006 University of Washington 35

Th

e I

nfo

rmati

on

Sch

ool

of

the U

niv

ers

ity o

f W

ash

ing

ton

Questions

• Suppose I wanted a database to run a wine review web site.

» What would some entities be?

» What would some attributes be of those entities?