The Entity-Relationship Model ER Model - Part 1: Basics
By Michael Hahsler Based on slides for CS145 Introductjon to Databases (Stanford)
The Entity-Relationship Model ER Model - Part 1: Basics By Michael - - PowerPoint PPT Presentation
The Entity-Relationship Model ER Model - Part 1: Basics By Michael Hahsler Based on slides for CS145 Introductjon to Databases (Stanford) Introduction to Database Design 2 Database Design Database design: Why do we need it? Agree on
By Michael Hahsler Based on slides for CS145 Introductjon to Databases (Stanford)
2
3
implementatjon
4
5
6
7
Makes Product name category price Company name
ER Model & Diagrams
Peter Chen, 1976
8
9
which are members of entjty types
in our model
Michael is an entjty.
10
Product Person
11
Product name category price Shapes are
used here are not. Shapes are
used here are not.
12
Product name category price Entity type
Product
Name: Xbox Category: Gamming Console Price: $250 Name: My Little Pony Doll Category: T
Price: $25
Entity Entity Attribute Entities are not explicitly represented in ER diagrams!
13
Product name category price
Denote elements of the primary key by underlining. Denote elements of the primary key by underlining.
Here, {name, category} is not a key (it is not minimal). If it were, what would it mean?
The ER model forces us to designate a single primary key, though there may be multiple candidate keys. Often, we introduce an artifjcial key attribute (also called a synthetic or surrogate key). The ER model forces us to designate a single primary key, though there may be multiple candidate keys. Often, we introduce an artifjcial key attribute (also called a synthetic or surrogate key).
14
Product name category price
name category price Gizmo Electronics $9.99 GizmoLite Electronics $7.50 Gadget Toys $5.50
Product
15
Product name category price Company name Makes
16
makes buys Product name category price Person address name ssn Company stockprice name
17
1 2 3 a b c d A= B=
18
(a,b)
(2,d), (3,a), (3,b), (3,c), (3,d)}
1 2 3 a b c d A= B=
19
(a,b)
(2,d), (3,a), (3,b), (3,c), (3,d)}
1 2 3 a b c d A= B=
R = {(1,a), (2,c), (2,d), (3,b)}
20
makes Company Product
1 2 3 a b c d A= B=
21
name category price Gizmo Electronics $9.99 GizmoLite Electronics $7.50 Gadget Toys $5.50 name GizmoWorks GadgetCorp
Product Company Makes Product name category price Company name
A relationship between entity sets P and C is a subset
uniquely identifjed by P and C’s keys A relationship between entity sets P and C is a subset
uniquely identifjed by P and C’s keys
22
name category price Gizmo Electronics $9.99 GizmoLite Electronics $7.50 Gadget Toys $5.50 name GizmoWorks GadgetCorp
Product Company
C.name P.name P.category P.price GizmoWorks Gizmo Electronics $9.99 GizmoWorks GizmoLite Electronics $7.50 GizmoWorks Gadget Toys $5.50 GadgetCorp Gizmo Electronics $9.99 GadgetCorp GizmoLite Electronics $7.50 GadgetCorp Gadget Toys $5.50
Company C Product P Makes Product name category price Company name
A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identifjed by P and C’s keys A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identifjed by P and C’s keys
23
name category price Gizmo Electronics $9.99 GizmoLite Electronics $7.50 Gadget Toys $5.50 name GizmoWorks GadgetCorp
Product Company
C.name P.name P.category P.price GizmoWorks Gizmo Electronics $9.99 GizmoWorks GizmoLite Electronics $7.50 GizmoWorks Gadget Toys $5.50 GadgetCorp Gizmo Electronics $9.99 GadgetCorp GizmoLite Electronics $7.50 GadgetCorp Gadget Toys $5.50
Company C Product P
C.name P.name GizmoWorks Gizmo GizmoWorks GizmoLite GadgetCorp Gadget
Makes Makes Product name category price Company name
A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identifjed by P and C’s keys A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identifjed by P and C’s keys
24
This follows from our mathematical defjnition
set) This follows from our mathematical defjnition
set)
Makes Product name category price Company name
KeyMakes = KeyProduct KeyCompany
25
Product name category price Company name Makes since Relatjonships may have atuributes as well. For example: “since” records when company started making a product For example: “since” records when company started making a product
Note: For each product/company pair there is automatically only a single since value since there can only be one unique product/ company pair in makes. Note: For each product/company pair there is automatically only a single since value since there can only be one unique product/ company pair in makes.
26
Purchased Product name category price Person name date
Modeling something as a relationship makes it
Modeling something as a relationship makes it
27
Product name category price Person name date Purchase quantjty PID# ProductOf BuyerOf
We can always use a new entity instead of a relationship. For example, to permit multiple instances of each entity combination! We can always use a new entity instead of a relationship. For example, to permit multiple instances of each entity combination!
28
name category price Gizmo Electronics $9.99 GizmoLite Electronics $7.50 Gadget Toys $5.50
Product Makes Product name category price Company name
Relatjonship/Relatjonship type Relatjon
ER Model: How do Entjty types relate to each other Math: A Relatjon (= a subset of the cross product) Relatjonal Algebra: A table with data (a set)
Relations are used to implement entity types and certain relationship types! Relations are used to implement entity types and certain relationship types!
29
30
31
Identjfy entjty types and atuributes (nouns):
Identjfy relatjonship types (verbs):
32
Identjfy Entjty types (bold) and atuributes:
Identjfy relatjonship types:
33
Make its own entjty type
34
make buy Product name category price Customer address name ID Manufacturer name phone
35
T eams play each other in
pair of teams can play each
times Players belong to T eams (assume no trades / changes) A Play will contain either a Pass from one player to another, or a Run by one player A Game is made up of Plays that result in a yardage gain/loss, and potentially a touchdown