cs 377 database systems - emory universitylxiong/cs377_f11/share/slides/05_ermapping.pdf · for...
TRANSCRIPT
CS 377
Database Systems
1
ER-to-Relational Mapping
Li Xiong
Department of Mathematics and Computer Science
Emory University
Requirement analysis
Requirement specification
Conceptual design
Conceptual data model (ER Model)
Logical design
2
Logical design
Representational data model (Relational Model)
Physical design
Physical data model
Database design implementation
ER Diagram of Company Database
3
4
ER-to-Relational Mapping
Step 1: Mapping of Regular Entity Types
Step 2: Mapping of Weak Entity Types
Step 3: Mapping of Binary 1:1 Relation Types
Step 4: Mapping of Binary 1:N Relationship Types.
Step 5: Mapping of Binary M:N Relationship Types.
Step 6: Mapping of Multivalued attributes.
5
Step 6: Mapping of Multivalued attributes.
Step 7: Mapping of N-ary Relationship Types.
Chen, Peter P. (1976). "The Entity-Relationship Model Toward a Unified View of Data". ACM Transactions on Database Systems 1 (1): 9-36.
Step 1: Mapping of Regular Entity Types.� For each regular (strong) entity type, create a relation R that
includes all the simple attributes (or simple component attributes of a composite attribute) of E.
� Choose one of the key attributes of E as the primary key for R.
6
Step 2: Mapping of Weak Entity Types
� For each weak entity type W with owner entity type E, create a relation R and
include all simple attributes (or simple components of composite attributes) of
W as attributes of R.
� Include primary key of E as foreign key of R, the primary key of R is the
combination of the primary key(s) of E and the partial key of W, if any.
7
Step 3: Mapping of 1:1 Binary Relationship Types� Foreign key approach (expand a relation)
� choose a relation S and include as foreign key the primary key of T; include simple relationship attributes - which relation to choose as S?
� Merge two relations - when is it appropriate?
� Create a new relation� Create R and include as foreign keys the primary keys of S and T; primary key of R is one of the foreign keys – drawback? when is it better?
8
Step 4: Mapping of 1:N Binary Relationship Types
� Foreign key approach (expand a relation)� choose a relation S and include as foreign key the primary key of T; include simple relationship attributes - which relation to choose as S?
� Create a new relation� Create R and include as foreign keys the primary keys of S and T; primary key of R is one of the foreign keys – when is it better than the foreign key approach?
� Why is merged relation approach not appropriate?
9
Step 5: Mapping of M:N Binary Relationship Types
� Create a new relation� Create R and include as foreign keys the primary keys of S and T; primary key of R is one of the foreign keys
� Why is foreign key approach and merged relation approach not appropriate?
10
Step 6: Mapping of Multivalued attributes.
� For each multivalued attribute A, create a new relation R. Include the attribute
A and the primary key attribute as a foreign key in R
� What’s the primary key of R?
11
� For each n-ary relationship type R (n>2), create a new relation S
� Include as foreign key the primary keys of the participating entity types
� include any simple attributes of the n-ary relationship type (or simple components of composite attributes) as attributes of S
Step 7: Mapping of N-ary Relationship Types
12
13
Summary of Mapping
ER Model Relational Model
Entity type “Entity” relation
1:1 or 1:N relationship type Foreign key (or “relationship” relation)
M:N relationship type “Relationship” relation and two foreign keys
14
M:N relationship type “Relationship” relation and two foreign keys
n-ary relationship type “Relationship” relation and n foreign keys
Simple attribute Attribute
Composite attribute Set of simple component attributes
Multivalued attribute Relation and foreign key
Key attribute Primary (or secondary) key
In-Class Exercise
15
Exercise 9.4. Map the ER schema for a SHIP_TRACKING database into a relational schema and
specify all primary keys and foreign keys.