文档介绍:Unit 3
Entity-Relationship Model
2017/11/10
1
Outline
The Entity-Relationship Model
Basic Elements of the ER Model
Entities, Relationships, Rings ,Attributes
Other Elements of the ER Model
Generalization hierarchies
posite attributes
Identifiers
Weak entity
Reading the ER Diagrams
2017/11/10
2
The Entity-Relationship Model
A database can be modeled as:
a collection of entities,
relationships among entities.
Basic elements of ER model
Entities
Relationships
Rings
Attributes
2017/11/10
3
Entity
Entity is a class of real-world objects.
entities
object or
data instance
PERSON = {p1,p2,p3}
CITY={c1,c2,c3}
用矩形表示 entity
PERSON
CITY
2017/11/10
4
Relationship
Relationship is the aggregation of two or more entities.
用菱形表示 relationship
aggregation
object
LIVES_IN={<p1,c1>, <p2,c3>,<p3,c3>}
表達某人住在某城市的關係
IS_BORN_IN={<p1,c1>,<p2,c2>,<p3,c1>}
表達某人在某城市出生的關係
LIVES_IN
IS_BORN_IN
2017/11/10
5
PERSON = {p1,p2,p3}
CITY={c1,c2,c3}
LIVES_IN={<p1,c1>, <p2,c3>,<p3,c3>}
IS_BORN_IN={<p1,c1>,<p2,c2>,<p3,c1>}
p1
p2
p3
PERSON
c1
c2
c3
CITY
LIVES_IN
p1
p2
p3
PERSON
c1
c2
c3
CITY
IS_BORN_IN
2017/11/10
6
CLASSROOM
COURSE
DAY
MEETS
MEETS 為 relationship 表達出某課程星期幾在哪個教室上課
2017/11/10
7
Ring
Binary relationship connecting an entity to itself. (recursive relationship)
EMPLOYEE
MANAGES
SUBORDINATE_TO
(直屬上司)
MANAGER_OF (管那些人)
若 EMPLOYEE 包含有九個 objects 如下:
EMPLOYEE={p1,p2,p3,p4,p5,p6,p7,p8,p9}
p1
p2
p4
p3
p5
p6
p8
p7
p9
MANAGES={(p1,p2),(p1,p3),(p1,p4),(p3,p5),(p3,p6),(p4,p7),(p4,p8),(p4,p9)}
(0,n)
(0,1)
2017/11/10
8
Cardinality on relationship
CLASSROOM
COURSE
DAY
MEETS
(0,40)
(0,n)
(1,3)
(0,n)
(1,1)
(1,1)
(0,n)
CITY有可能沒人住
最多可住 n 人
每個人至少一個出生地
最多一個出生地
2017/11/10
9
Attributes
Attributes represent elementary properties of entities or relationships.
Attributes 也有 min-max card
min(A,E) 代表 attribute A 的值對應於 entity E 中的 object 出現的最少次數.
max(A,E) 代表 attribute A 的值對應於 entity E 中的 object 出現的最多次數.
PERSON
NAME
SOCIAL