Upload
rudolph-hutchinson
View
216
Download
1
Embed Size (px)
Citation preview
CSC 110 -Intro. to Computing
Lecture 10:
Databases
Announcements
Enjoy the long weekend!
Bob Jones 7 Elvis Gates 4Sam Smith 12 Steve Young 12Tom Jones 10 Bob Bledsoe 7Jim Mower 8 Michael Jones 4Bob DeNiro 7 Jack Woods 10Greg Martin 6 Josh Jones 9Mike Marino 2 Bob Martin 7Jim Woods 6 Fran McLean 12Bob Denver 7 Clive Deeker 4Xavier Jobs 11 Matthew Hertz 8Sam Els 3 Zoe Elton 9Ernie Smith 9 Kate Bolter 10
Bob Jones 7 Elvis Gates 4Sam Smith 12 Steve Young 12Tom Jones 10 Bob Bledsoe 7Jim Mower 8 Michael Jones 4Bob DeNiro 7 Jack Woods 10Greg Martin 6 Josh Jones 9Mike Marino 2 Bob Martin 7Jim Woods 6 Fran McLean 12Bob Denver 7 Clive Deeker 4Xavier Jobs 11 Matthew Hertz 8Sam Els 3 Zoe Elton 9Ernie Smith 9 Kate Bolter 10
Problems With Humans
Humans cannot process large amounts of dataGet overwhelmed, lost, and miss patterns
(Other) people may also make mistakes
Patterns and trends are important, however Suggest methods of improving business Identify new possibilities that can be exploited Hints at unknown relationships
One Solution: Databases
Databases are programs that store and manage information automaticallyTypically used when data is frequently added,
modified, or searched forExamples of databases:
Prices & orders from amazon.com Student records in a college Phone calls made/received from a phone number Card catalogue in a library
Why Databases Are Useful
Computers process 1 data item as easily as they process 10 or 10 billion itemsFilter data to return only certain elements
E.g., Only consider results for people named “Bob”
Evaluate results on a minute-by-minute basis E.g. Have we made our sales goals yet?
Combine data that are somehow related Let the user look for missed relationships
Relational Databases
Most common databases today Uses relationships to organize data Starts with a table
Each table contains a collection of records Every record uses identical fields, but may have different
values Fields must include at least one unique identifier
Database usually contain multiple tables And define how to combine data between tables
Commonly Used Database
Database Organization
Databases contain several different piecesPhysical database – File(s) holding the tablesDatabase engine – Software enabling programs
and users to read, write, and modify database contents
Database schema – Files specifying what type of data each field in a table stores; also specifies what fields enable tables to relate to one another
Physical Database
Specifies how data are storedHas little/no relation to anything else about the
databaseUsually uses many files to store all the data
Little relationship between files and the data
Physical database is only meant to be accessed by database engineMay not make sense to actual people
Database Schema
Specifies what the type of data each field stores
Used to interpret the file(s) storing each tableExample schema for Movie table:
Movie (MovieId: key; Title, Genre: text; Rating: Enum)
Database Engine
Program which must be used to access database Interprets database schema to get/store
information in physical databaseEnsures requests match what is expected by
databaseVerifies program/user requesting or modifying
data is allowed to do so
SQL
Stands for Structured Query LanguageUsually pronounced “sequel”
Language used by database engines Includes commands retrieve, add, remove,
and modify records Expects/requires commands to be given in
a very specific format
SQL Query Format
select Name from StudentReturns Name in each record in Student table
select Name from Student where StudentId =2009348Return the Name of any Student with a StudentId of
2009348 select Name from Student order by NameReturns sorted list of Names from Student
SQL Query Format
select * from StudentReturn all records from Movie table
select * from Student where name like ‘John’ order by StudentIdReturn all records from the Student table,
sorted by their id numbers, whose name includes a word like “John”
Database Design
Designing good databases is a tricky, complex processNo single solution works for all dataOften the “best” design is a matter of
interpretation But, bad designs limits data’s usefulness
May limit what data can be storedCannot access information across tables
ER Modeling
ER stands for Entity-Relationship Common way of designing databases
Ignores “real-world” issues, implementationStarts at important data to storeEvaluates relationships between the data
Builds tables and fields from there
One popular tool for ER modeling is ER diagram
ER Diagram
Start with boxes Each box captures single concept we wish
to consider/captureBox labels are usually singular nounShould describe important actor in
relationship being modeled
Problem Use Homework
ER Diagram
Add ovals around each of the boxesRepresent important attributes of each box
Labels should be simple, declarative noun
Include all details we might want to captureEach oval should define single piece of data
Problem Use Homework
ProblemId
Answer
Question Number
PctCorrect
HomeworkId
DateDue Avg Score
DateGiven
ER Diagram
Show relationships between boxesDraw line whenever we may wish to connect
dataTurn boxes that in middle of relationship into
diamonds
Problem Homework
ProblemId
Answer
Question Number
PctCorrect
HomeworkId
DateDue Avg Score
DateGiven
Use
ER Diagram
Now build databaseBoxes and diamonds become tablesOvals become fields of the tableLinks between tables suggest tables should
share at least 1 field in common
Problem Homework
ProblemId
Answer
Question Number
PctCorrect
HomeworkId
DateDue Avg Score
DateGiven
Use
For Next Lecture
Finish reading Chapter 12 Be prepared to discuss:
Spreadsheets