Download presentation
Presentation is loading. Please wait.
Published byCaroline Louise Cloutier Modified over 6 years ago
1
Lecture 06 Data Modeling: E/R Diagrams
Monday, October 10, 2005
2
Outline E/R diagrams (Chapter 2)
From E/R diagrams to relations (3.2, 3.3) The relational data model: 3.1 Next time: Functional dependencies: 3.4
3
Converting Multi-way Relationships to Binary
ProductOf date Product Purchase StoreOf Store BuyerOf Person
4
From E/R Diagrams to Relational Schema
Entity set relation Relationship relation
5
Entity Set to Relation name category price Product
Product(name, category, price) name category price gizmo gadgets $19.99
6
Relationships to Relations
price name category Start Year name makes Company Product Stock price Makes(product-name, product-category, company-name, year) Product-name Product-Category Company-name Starting-year gizmo gadgets gizmoWorks (watch out for attribute name conflicts)
7
Relationships to Relations
price name category Start Year name makes Company Product Stock price No need for Makes. Modify Product: name category price StartYear companyName gizmo gadgets gizmoWorks
8
Multi-way Relationships to Relations
address name Product Purchase price Store name Purchase(prodName,stName,ssn) Person ssn name
9
3. Design Principles What’s wrong? Purchase Product Person President
Country Person Moral: be faithful!
10
Design Principles: What’s Wrong?
date Product Purchase Store Moral: pick the right kind of entities. personAddr personName
11
Design Principles: What’s Wrong?
date Dates Product Purchase Store Moral: don’t complicate life more than it already is. Person
12
Modeling Subclasses Some objects in a class may be special
define a new class better: define a subclass Products Software products Educational products So --- we define subclasses in E/R
13
Subclasses name category price Product isa isa Software Product
Educational Product platforms Age Group
14
Understanding Subclasses
Think in terms of records: Product SoftwareProduct EducationalProduct field1 field2 field1 field2 field3 field1 field2 field4 field5
15
Subclasses to Relations
Product Name Price Category Gizmo 99 gadget Camera 49 photo Toy 39 Product name category price isa Educational Product Software Product Age Group platforms Sw.Product Name platforms Gizmo unix Ed.Product Name Age Group Gizmo todler Toy retired
16
Difference between ODL and E/R inheritance
ODL: classes are disjoint (same for Java, C++) Product p1 p2 p3 sp1 sp2 ep1 ep2 ep3 EducationalProduct SoftwareProduct
17
Difference between ODL and E/R inheritance
E/R: entity sets overlap Product p1 p2 p3 sp1 sp2 ep1 ep2 ep3 EducationalProduct SoftwareProduct
18
No need for multiple inheritance in E/R
we have three entity sets, but four different kinds of objects Still needed if we want extra attributes Product p1 p2 p3 sp1 sp2 ep1 ep2 ep3 EducationalProduct SoftwareProduct esp2 esp1
19
Modeling Subclass Structure
Product ageGroup topic Platforms required memory isa isa Educational Product Software Product isa isa Educ-software Product Educational-method
20
Modeling UnionTypes With Subclasses
FurniturePiece Person Company Say: each piece of furniture is owned either by a person, or by a company
21
Modeling Union Types with Subclasses
Say: each piece of furniture is owned either by a person, or by a company Solution 1. Acceptable, imperfect (What’s wrong ?) FurniturePiece Person Company ownedByPerson
22
Modeling Union Types with Subclasses
Solution 2: better, more laborious Owner isa isa ownedBy Person Company FurniturePiece
23
Constraints in E/R Diagrams
Finding constraints is part of the modeling process. Commonly used constraints: Keys: social security number uniquely identifies a person. Single-value constraints: a person can have only one father. Referential integrity constraints: if you work for a company, it must exist in the database. Other constraints: peoples’ ages are between 0 and 150.
24
Keys in E/R Diagrams name category Underline: price Product
No formal way to specify multiple keys in E/R diagrams Person name ssn address
25
Single Value Constraints
makes v. s. makes
26
Referential Integrity Constraints
makes Product Company Each product made by at most one company. Some products made by no company makes Product Company Each product made by exactly one company.
27
Other Constraints makes <100 Product Company What does this mean ?
28
Weak Entity Sets Entity sets are weak when their key comes from other
classes to which they are related. affiliation Team University sport number name Notice: we encountered this when converting multiway relationships to binary relationships (last lecture)
29
Handling Weak Entity Sets
affiliation Team University sport number name Convert to a relational schema (in class)
30
The Relational Data Model
Schema Physical storage Data Modeling Have seen this in SQL Complex file organization and index structures. E/R diagrams Tables: column names: attributes rows: tuples Have seen this too Discuss next
31
Terminology Table name or relation name Attribute names Products:
Name Price Category Manufacturer gizmo $ gadgets GizmoWorks Power gizmo $ gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi We know this already… Tuples or rows or records
32
Schemas Relational Schema: Relation name plus attribute names
E.g. Product(Name, Price, Category, Manufacturer) Database Schema Set of relational schemas E.g. Product(Name, Price, Category, Manufacturer), Company(Name, Address, Phone) … We know this too…
33
Instances Relational schema = R(A1,…,Ak): Instance = relation with k attributes (of “type” R) Database schema = R1(…), R2(…), …, Rn(…) Instance = n relations, of types R1, R2, ..., Rn
34
Example Schema: Product(Name, Price, Category, Manufacturer) Instance:
gizmo $ gadgets GizmoWorks Power gizmo $ gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi
35
First Normal Form (1NF) A database schema is in First Normal Form if all tables are flat Student Student Name GPA Alice 3.8 Bob 3.7 Carol 3.9 Name GPA Courses Alice 3.8 Bob 3.7 Carol 3.9 Math DB OS Takes Course Student Course Alice Math Carol DB Bob OS Course Math DB OS DB OS May need to add keys Math OS
36
Normal Forms 1NF = rather trivial 3NF, BCNF = very subtle; next time
Other normal forms = in the book
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.