Download Introduction to SQL and Data Storage Technologies

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Entity–attribute–value model wikipedia , lookup

Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
SQL, Data Storage
Technologies, and Web-Data
Integration
Week 1
Today’s Agenda
•
•
•
•
•
Instructor Introduction
Review Syllabus
Student Introductions
Introduction to Unix and Course Servers
Introduction to Database Design
– 1st Normal Form
Databases
• A database is anything that can store data
– text file, spreadsheet, custom file, filing
cabinet, library
• Typically, one uses the word database to
mean a Database Management System
(DBMS)
DBMS
• A DBMS handles the storage and retrieval
of data for you, in a very efficient way
• It also provides persistence and access
control.
• Example uses:
– Airline reservation systems, banking systems,
corporation records.
Relational DBMS
• Some of the more popular DBMS’s are
Relational DBMS’s (RDBMS)
– Oracle, IBM DB2, MySQL
• Allows the definition of relationships
between separate pieces of data
• Structured Query Language (SQL) allows
a standard way of communicating to a
RDBMS
RDBMS
• Using and interacting with a RDBMS,
specifically MySQL, will be the focus of
this class.
• The first step towards using a RDBMS is
designing your database
Database Design
• A good database starts with a good
database design.
• This is typically done with a data model
• To start a data model, we need to list all
the data we need to store.
Sources for a Data Model
• Design documents
– Requirements
– Functional Specifications
– Screen shots
– Technical Specifications
• Brainstorming
• User interviews
• Use cases
Data Model Example
• We want to build a database for a nonprofit organization to track of donors, and
their donations to each of the
organization's divisions.
• Brainstorm a list that details some of the
data we will need to store.
Example Data Model
•
•
•
•
•
•
•
Donor Name
Donor Address
Donor Phone number
Donor E-mail
Donation Amount
Donation Date
Division Name
In Class Exercise
•
Brainstorm a list of data for the following
applications
1.
2.
3.
4.
5.
Recipes
Dating Service
Bookstore
Surveys
Movie Collection
Example Data Model
• How do we store this data? Begin by creating
some examples.
Donor
Name
Donor
Address
Donor
Phone #
Donor
Email
Donation Donation Prcessor Division
Amount
Date
Name
Name
Fred
Smith
123
Bedrock
5551212
f@fred 100.00
.com
01/02/04
Martha
Marketin
g
Beth
Kirsh
104
Ballard
5551234
b@kirs 250.00
h.com
12/11/04
Jim
Childcare,
trips
Erin
Lovett
1580
Stone Ln
5555098
e@eri
n.com
09/07/04
Jim
Childcare,trip
s
Fred
Smith
123
Bedrock
5551212
f@fred 100.00
.com
02/02/04
Jim
Childcare
10.00
Example Data Model
• Potential problems with one big table
• Repetitive data
– Extra work for data entry
– A lot of work for updating (what if Fred moves?)
• Donations to multiple divisions
–
–
–
–
–
Separated with commas?
Hard to search for?
How to update?
Limited number?
What if we want to know more about a division than
its name?
Example Data Model
• One big table is insufficient, we need a
better design.
• We can use a relational data model to
create a better design
– Entity-Relationship (ER) model
Entities
• A thing or object that we need to store
information about
• Specifically, it must be a “thing” that has
attributes and/or relationships to other
“things”
• Example: Person is probably an entity.
However, “first name” is probably not an
entity.
• What are the entities in our data model?
Entity Attributes
• An attribute is a descriptive piece of
information about an entity.
• Attributes might be any data type
– numbers, character strings, dates, times, etc.
• An attribute can only describe a single
entity
• What attributes do our Entities need?
ER Diagrams
• We can model our Entities and Attributes inside
an ER Diagram.
Entities and Objects
• In programming, Objects tend to be
focused on behaviors
• Entities are focused on attributes, which
Objects tend to hide
• Both PHP & JavaScript support Objects,
which we can use to model an Entity
PHP Objects
<?php
class Donor {
var $name;
var $address;
var $email;
var $phone;
function make_donation($donation) {
…
}
}
?>
JavaScript Objects
• JSON: JavaScript Object Notation
var donor = {
name: “Fred”,
address: “123 Bedrock”,
phone: “555-1212”,
email: “[email protected]”
};
JavaScript Objects
function Donor(name) {
this.name = name;
this.address = “”;
this.setAddress(address) {
this.address = address;
}
this.make_donation(donation) {
…
}
}
Normalization
• Soon after the RDBMS was invented, the
idea of database normalization was
invented.
• Normalization helps to remove
redundancy and create a scalable design
• There are numerous levels and types of
normalization.
First Normal Form
• First Normal Form (1NF) occurs when all
attributes are single valued.
– No repeating or attributes with multiple values
• Examples:
– A Movie entity with attributes actor1, actor2,
actor3.
– A Sundae entity with a toppings attributes
• Is our data model in 1NF?
Example Data Model
• Our “Division Name” is not in 1NF
– Contains multiple values
– Isn’t really an attribute of a Donation
– Better suited as an attribute of a Division
• One solution is to make the attribute into a
new entity
– Create a Division entity, with a Division Name
attribute
Example Data Model
In Class Exercise
•
Create an Data Model in 1st Normal Form
for the following applications:
1.
2.
3.
4.
5.
Recipes
Dating Service
Bookstore
Surveys
Movie Collection