Vous êtes sur la page 1sur 6

Midterm

•  Next Monday in class


Introduction to Data Management •  Content:
CSE 344 –  Lectures 1 through 13
–  Homework 1 through 4
•  Open books and open notes
–  But no portable devices (no laptops, no phones, etc.)
Lecture 14: E/R Diagrams •  Three questions:
–  Question 1: SQL and Physical tuning
–  Question 2: Relational algebra, calculus, datalog
–  Question 3: XML/XPath/XQuery

Magda Balazinska - CSE 344, Fall 2011 1 Magda Balazinska - CSE 344, Fall 2011 2

How To Study Today: E/R Diagrams


•  Go over the lecture notes Motivating scenario
•  Read the book •  Customer asks you to help them setup a DBMS
•  Go over the homeworks
•  They want to store information about
•  Practice
–  Companies and various branches inside companies
–  Practice webquiz will be posted Tuesday or Wednesday
•  Each company has a name, an address, and a CEO
–  Look at the midterm from 344 Spring 2011
•  Each company also has a list of key employees
–  Look at both midterm and final from 444 past years
•  Look for questions about SQL, relational algebra, and XML/Xpath
•  Each branch has a name and a market share in $$$

•  Ask Kristi and me questions –  Products manufactured by these companies


•  Each product has a name and a description
•  The goal of the midterm is to help you learn!
•  Products are manufactured by different branches
Magda Balazinska - CSE 344, Fall 2011 3 Magda Balazinska - CSE 344, Fall 2011 4

Database Design Database Design Process


name

Conceptual Model: Patient patien_of Doctor

•  Why do we need it? zip name dno

–  Need a way to model real world entities in terms of relations


–  Not easy to go from real-world entities to a database schema Relational Model:
•  Consider issues such as: Tables + constraints
–  What entities to model And also functional dep.
–  How entities are related
–  What constraints exist in the domain Normalization:
–  How to achieve good designs Eliminates anomalies
•  Several formalisms exists Conceptual Schema
–  We discuss E/R diagrams
Physical storage details
Magda Balazinska - CSE 344, Fall 2011 5 Physical Schema

1
name category
name
Entity / Relationship Diagrams
This is an price
entity set
Objects entities makes Company
Product Product
Classes entity sets
stockprice
Attributes are like in ODL address
(ODL = Object Definition Language)
buys
employs
Relationships: like in ODL except buys
Person
- first class citizens (not associated with classes)
- not necessarily binary

Magda Balazinska - CSE 344, Fall 2011 7 address name ssn 8

Keys in E/R Diagrams What is a Relation ?


•  Every entity set must have a key •  A mathematical definition:
–  if A, B are sets, then a relation R is a subset of A × B
•  A={1,2,3}, B={a,b,c,d},
name category 1 a
A × B = {(1,a),(1,b), . . ., (3,d)}
R = {(1,a), (1,c), (3,b)} 2 b
price A=
c
3
B= d
Product •  makes is a subset of Product × Company:
makes Company
Product
Magda Balazinska - CSE 344, Fall 2011 9 Magda Balazinska - CSE 344, Fall 2011 10

name category
name
Multiplicity of E/R Relations
price
•  one-one: makes Company
1 a
2 b Product
3 c
•  many-one d
stockprice
1 a
What does
2 b this say ?
3 c buys
d employs
•  many-many
1 a
Person
2 b
3 c
d

Magda Balazinska - CSE 344, Fall 2011 11 address name ssn 12

2
Multi-way Relationships Arrows in Multiway Relationships
How do we model a purchase relationship between buyers,
Q: What does the arrow mean ?
products and stores?

Product Product

Purchase Store
Purchase Store

Person
Person
A: A given person buys a given product from at most one store
Can still model as a mathematical set (how ?) 13 Magda Balazinska - CSE 344, Fall 2011 14

Arrows in Multiway Relationships Arrows in Multiway Relationships


Q: What does the arrow mean ? Q: How do we say that every person shops at at most one store ?

Product Product

Purchase Store Purchase Store

Person Person
A: A given person buys a given product from at most one store A: Cannot. This is the best approximation.
AND every store sells to every person at most one product (Why only approximation ?)
Magda Balazinska - CSE 344, Fall 2011 15 Magda Balazinska - CSE 344, Fall 2011 16

Converting Multi-way 3. Design Principles


Relationships to Binary
What’s wrong?
date
ProductOf Product
Product Purchase Person

Purchase
StoreOf Store
Country President Person

BuyerOf Moral: be faithful to the specifications of the app!


Person
17 Magda Balazinska - CSE 344, Fall 2011 18
Magda Balazinska - CSE 344, Fall 2011

3
Design Principles: Design Principles:
What’s Wrong? What’s Wrong?
date
Dates date
Product
Product
Purchase Store
Purchase Store
Moral: pick the right
kind of entities. Moral: don’t
personAddr complicate life more
personName than it already is.
Magda Balazinska - CSE 344, Fall 2011 19 Person 20

From E/R Diagrams Entity Set to Relation


to Relational Schema
name category

•  Entity set  relation


price
•  Relationship  relation
Product

Product(name, category, price)

name category price

gizmo gadgets $19.99


Magda Balazinska - CSE 344, Fall 2011 21 22

Relationships to Relations Relationships to Relations


price name category price name category
Start Year Start Year
name name

makes Company makes Company


Product Product

Stock price Stock price


Makes(product-name, product-category, company-name, year) No need for Makes. Modify Product:
Product-name Product-Category Company-name Starting-year
name category price StartYear companyName
gizmo gadgets gizmoWorks 1963
gizmo gadgets 19.99 1963 gizmoWorks
23 24
(watch out for attribute name conflicts)

4
Multi-way Relationships to
Modeling Subclasses
Relations
name address
Product
Some objects in a class may be special
•  define a new class
Purchase Store •  better: define a subclass
name price
Products
Purchase(prodName,stName,ssn)
Software Educational
Person products products

ssn name So --- we define subclasses in E/R


Magda Balazinska - CSE 344, Fall 2011 25 Magda Balazinska - CSE 344, Fall 2011 26

Subclasses
name category Understanding Subclasses
price
•  Think in terms of records: field1
–  Product field2
Product
–  SoftwareProduct field1
field2
isa isa –  EducationalProduct field3

field1
Software Product Educational Product field2
field4
field5
Magda Balazinska - CSE 344, Fall 2011 Magda Balazinska - CSE 344, Fall 2011 28
platforms Age Group

Subclasses to Product
Relations Name Price Category
Modeling UnionTypes With
name category Gizmo 99 gadget Subclasses
Camera 49 photo
price
Toy 39 gadget FurniturePiece
Product

Sw.Product Name platforms


isa isa Company
Gizmo unix Person

Software Product Educational Product Ed.Product


Age
platforms Age Group Name Say: each piece of furniture is owned
Group
Other ways to convert are possible Gizmo todler either by a person or by a company
See book sec 4.6 Toy retired
Magda Balazinska - CSE 344, Fall 2011 29 Magda Balazinska - CSE 344, Fall 2011 30

5
Modeling Union Types with Modeling Union Types with
Subclasses Subclasses
Say: each piece of furniture is owned either by a Solution 2: better, more laborious
person or by a company Owner
Solution 1. Acceptable but imperfect (What’s wrong ?)
Person FurniturePiece Company isa isa

ownedBy
Person Company
ownedByPerson ownedByComp.
FurniturePiece
Magda Balazinska - CSE 344, Fall 2011 31 Magda Balazinska - CSE 344, Fall 2011 32

Vous aimerez peut-être aussi