Chapter 2 - A - ER - Model
Chapter 2 - A - ER - Model
Entity- Relationship
Model
COMP3278 Introduction to
Database Management Systems
3
Section 2A.1
5
Entity and Entity set
Entity
An object that exists and is distinguishable from other objects.
E.g., A customer, an account, a department, etc.
customer_id account_
balance
customer account
8
Relationship and Relationship set
In the E-R Diagram
Diamonds – relationship sets
customer_id account_
balance
name
customer
address
? owner
? account
account_id 9
Constraints
Mapping cardinalities
Concerns the number of entities to which another
entity can be associated via a relationship set.
E.g., For each customer, how many accounts
he/she can have? One or more than one?
Participation constraints
Concerns whether all entities in the entity set have
to participate in the relationship set.
E.g., Whether a customer must have an account
record, or there can be some customers without
any accounts?
10
Mapping cardinalities
We express cardinality constraints by drawing either a
directed line (→), signifying “one,” or an undirected
line (—), signifying “many,” between the relationship
set and the entity set.
account_
customer_id
balance
11
Mapping cardinalities
A customer can have at most one account.
account_
customer_id
balance
12
Mapping cardinalities
A customer can have more than one accounts.
account_
customer_id
balance
13
Mapping cardinalities
An account can be associated with at most one
customer.
account_
customer_id
balance
14
Mapping cardinalities
An account can be associated with more than one
customers.
account_
customer_id
balance
15
Mapping cardinalities
Please build a system to store the customer and account
information of our bank. For each customer, we record
his/her customer ID, name and address; for each
account, we record its account ID and account balance.
Each customer can have one or more accounts, and
each account has to be owned by only one customer.
customer account
16
Mapping cardinalities
Please build a system to store the customer and account
information of our bank. For each customer, we record
his/her customer ID, name and address; for each
account, we record its account ID and account balance.
Each customer can have one or more accounts, and
each account has to be owned by only one customer.
17
Mapping cardinalities
Please build a system to store the customer and account
information of our bank. For each customer, we record
his/her customer ID, name and address; for each
account, we record its account ID and account balance.
Each customer can have one or more accounts, and
each account has to be owned by only one customer.
account_
customer_id Step3. Identify the attributes. balance
18
Mapping cardinalities
Please build a system to store the customer and account
information of our bank. For each customer, we record
his/her customer ID, name and address; for each
account, we record its account ID and account balance.
Each customer can have one or more accounts, and
each account has to be owned by only one customer.
account_
customer_id Step4. Mapping cardinalities. balance
One to one.
a b
20
Participation constraints
Concerns whether all entities in the entity set have to
participate in the relationship.
Total participation (indicated by double line): every
entity in the entity set participates in at least one
relationship in the relationship set.
21
Participation constraints
Each customer must have an account.
Total participation: All customers must participate in
the owner relationship.
account_
customer_id
balance
account_
customer_id
balance
account_
customer_id
balance
26
Exercise
Mapping cardinality
No arrow head (Many) Arrow head (One)
Each course can be taken by many students. Each student takes one course only.
27
Exercise
Mapping cardinality
No arrow head (Many) Arrow head (One)
Each course can be taken by many students. Each student takes one course only.
30
Practical issues
Please build a system to store the customer and account
information of our bank. For each customer, we record
his/her customer ID, name and address; for each account,
we record its account ID and account balance.
customer
? owner
? account
Candidate keys
Primary key
32
Super key
A super key of an entity set is a set of one or more
attributes whose values uniquely determine each
entity.
No two entities have exactly the same values in super
key.
In this example, if each customer has his/her
unique customer_id, then
{customer_id} is a super key.
customer_id {customer_id, name} is another super key.
{customer_id, address} is another super key.
{customer_id, name, address} is also a super key.
customer
name address
33
Candidate key
A candidate key of an entity set is a minimal super
key.
Minimal – no redundant attributes, i.e., no subset of
a candidate key is still a key.
Although the following are super keys:
{customer_id}, { customer_id, name},
{customer_id, address},
customer_id {customer_id, name, address}
Only the {customer_id} is a candidate
customer key because it is minimal.
account_
customer_id
balance
customer account
37
Different attribute types
Single v.s. Composite attributes
Single attribute customer Composite attributes
Component attributes
38
Different attribute types
Single-valued v.s. Multi-valued attributes
Multi-valued attributes are represented by double ellipses
in the E-R Diagram.
customer Multi-valued attribute
Derived attribute 40
Weak Entity Set
An entity set that does not have a primary key is
referred to as a weak entity set.
The existence of a weak entity set depends on the
existence of an identifying entity set.
We need the identifying entity set to help to uniquely
identify the entities in the weak entity set.
team player
48
Weak Entity Set
Identifying entity set Identifying relationship set Weak entity set
employee works-for
worker
emplyee_name phone_number
employee works-for
worker
emplyee_name phone_number
Cardinality
An employee (worker) works for one manager.
An employee (manager) can have more than one workers
work for him/her.
52
Role
Entity sets of a relationship need not be distinct.
emplyee_id
manager
employee works-for
worker
emplyee_name phone_number
Participation
An employee (worker) may not work for any manager.
An employee (manager) can have no workers work for
him/her.
53
Specialization and Generalization
Specialization
We designate sub-groupings within an entity set that are
distinctive from other entities in the set.
A lower-level entity set inherits all
attributes and relationship set MSc student
participation of the higher-level
entity set to which it is linked.
Lower-level entity set can have its
own attributes. ISA
Full-time Part-time
student student
54
Specialization and Generalization
Total or partial
Specifies whether an entity in the higher level-entity set
must belong to at least one of the lower-level entity sets
within a specialization.
Total specialization:
MSc student
An MSc student MUST BE either
a full-time student or a part-
time student, so all MSc
students must participate in this ISA
specialization.
Full-time Part-time
student student
55
Specialization and Generalization
Total or partial
Specifies whether an entity in the higher level-entity set
must belong to at least one of the lower-level entity sets
within a specialization.
story_book comic
56
Specialization and Generalization
Disjoint or overlapping
Constraints on whether entities may belong to more than
one lower-level entity set within a single specialization.
Disjoint specialization:
MSc student
An MSc student must be either a
full-time student or a part-time
student, so the specialization is
disjoint. We use a keyword ISA Disjoint
“Disjoint” to indicate it.
Full-time Part-time
student student
57
Specialization and Generalization
Disjoint or overlapping
Constraints on whether entities may belong to more than
one lower-level entity set within a single specialization.
story_book comic
58
Chapter 2A.
END
COMP3278 Introduction to
Database Management Systems