Lecture3-ER 2 Rel
Lecture3-ER 2 Rel
Attributes
Relationship
• Attributes on relationships
• Multiplicity
• Binary versus n-ary relationships
• ISA relationships
TODAY’S TOPICS
Understand • Understand the real-world domain being modeled
For (1,1)-(1,1) relationships. We make one entity’s primary key another entity’s foreign
key and vice versa.
The same for (1,1)-(1,n) relationships, we don’t establish a new schema but bring the
primary key from the (1,n) entity into the (1,1) entity to make a foreign key.
For (1,n)-(1,n) relationships, we establish a new schema containing the primary keys of
the entities that formed it and its own attributes.
Add as a foreign key all of the primary key attribute(s) in the entity
corresponding to the owner entity type
The primary key is the combination of all the primary key attributes
from the owner and the partial key of the weak entity, if any
Three approaches
• Foreign Key
• Usually appropriate
• Merged Relation
• Possible when both participations are total
• Relationship Relation
• Not discussed
Choose one relation as S, the Better if S has total participation
other T (reduces number of NULL values)
DEPARTMENT
Dname Dnumber
PROJECT
Add as a foreign key all of the primary key attribute(s) in the entity
corresponding to the owner entity type
The primary key is the combination of all the primary key attributes
from the owner and the partial key of the weak entity, if any
EMPLOYEE
DEPARTMENT
Dname Dnumber
PROJECT
DEPENDENT
• Foreign Key
• Usually appropriate
• Merged Relation
• Possible when both participations are total
• Relationship Relation
• Not discussed
Choose one relation as S, the Better if S has total participation
other T (reduces number of NULL values)
DEPARTMENT
Dname Dnumber Mgr_ssn Mgr_start_date
1 2 3
Choose the S Add as a foreign Another approach:
relation as the key to S all of the create a
type at the N-side primary key relationship
of the relationship, attribute(s) of T relation
other is T
Create a new relation S (termed: Add as foreign keys the primary keys Add any simple attributes of the M :
relationship relation) of both relations; their combination N relationship to S
forms the primary key of S
In some ERD dialects, actually drawn in
1 2 3
Create a new relation S Add as foreign keys the Add the attribute to S (if
primary keys of the composite, the simple
corresponding relation attributes); the combination
of all attributes in S forms
the primary key
A. Multiple relations –subclass and superclass
▪ Usually works (assumes unique id at parent)
isa
color Ales
Beers
Name Manf
name Beers manf
Bud Anheuser-Busch
isa
Ales
Good for queries like “find the color of ales made by Pete’s.”
Beers
Name Manf
Bud Anheuser-Busch
Summerbrew Pete’s
Ales
Name Color
Summerbrew Drak
Good for queries like “find all beers (including ales) made by
Pete’s.”
Name Manf Color
Bud Anheuser- Null
Summerbrew Busch Drak
Pete’s
member
Users Groups
IsMemberOf
initiator
Member (uid, initiator_uid, gid)
• Similar to the idea of subclasses in object-oriented
programming: subclass = special case, fewer entities, and
possibly more properties
• Represented as a triangle (direction is important)
• Example: paid users are users, but they also get avatars (yay!)
uid gid
Users Groups
IsMemberOf
name name
ISA fromDate
PaidUsers
avatar Automatically “inherits” key, attributes, relationships
Entity-in-all-superclasses approach (“E/R style”)
• An entity is represented in the table for each subclass to which it
belongs
• A table includes only the attributes directly attached to the
corresponding entity set, plus the inherited key
uid gid
Users Groups
IsMemberOf Group (gid, name)
name name 〈142, Long〉 ∈ User (uid, name)
〈456, John〉
ISA fromDate
Member (uid, gid, from_date)
PaidUsers 〈456, ☺ 〉 ∈ PaidUser (uid, avatar)
avatar
Entity-in-most-specific-class approach (“OO style”)
• An entity is only represented in one table (the most specific entity
set to which the entity belongs)
• A table includes the attributes attached to the corresponding entity
set, plus all inherited attributes
uid gid
Users Groups
IsMemberOf
name name
ISA Group (gid, name)
fromDate
〈142, Long〉 ∈ User (uid, name)
PaidUsers Member (uid, gid, from_date)
avatar
〈456, Ralph, ☺〉 ∈ PaidUser (uid, name, avatar)
All-entities-in-one-table approach (“NULL style”)
• One relation for the root entity set, with all attributes found in the network of
subclasses (plus a “type” attribute when needed)
• Use a special NULL value in columns that are not relevant for a particular entity
uid gid
Users Groups
IsMemberOf
name name
ISA fromDate
PaidUsers Group (gid, name)
avatar 〈142, Long , NULL〉 ∈
User (uid, name, avatar)
〈456, John, ☺ 〉
Member (uid, gid, from_date)
Thank you for your attention!