0% found this document useful (0 votes)
15 views30 pages

Entity-Relationship Model123

Uploaded by

Bhaskar Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views30 pages

Entity-Relationship Model123

Uploaded by

Bhaskar Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Entity-Relationship Model

and Normalization
Modeling
• A database can be modeled as:
• a collection of entities,
• relationship among entities.
• An entity is an object that exists and is distinguishable from
other objects.
• Example: specific person, company, event, plant
• Entities have attributes
• Example: people have names and addresses
• An entity set is a set of entities of the same type that share the
same properties.
• Example: set of all persons, companies, trees, holidays
customer_id customer_name customer_street customer_city loan_number amount
Relationship Sets
• A relationship is an association among several entities
Example:
Hayes borrower L-14

A relationship set is a mathematical relation among n  2


entities, each taken from entity sets
{(e1, e2, … en) | e1  E1, e2  E2, …, en  En}

where (e1, e2, …, en) is a relationship


• Example:
(Hayes, L-14)  borrower
Relationship Set borrower
Relationship Sets (Cont.)
• An attribute can also be property of a relationship set.
• For instance, the depositor relationship set between entity sets
customer and account may have the attribute access-date
Degree of a Relationship Set
• Refers to number of entity sets that participate in a
relationship set.
• Relationship sets that involve two entity sets are binary
(or degree two). Generally, most relationship sets in a
database system are binary.
• Relationship sets may involve more than two entity sets.
Example: Suppose employees of a bank may have jobs (responsibilities) at
multiple branches, with different jobs at different branches. Then there is a ternary
relationship set between entity sets employee, job, and branch
Attributes
• An entity is represented by a set of attributes
Example:
customer = (customer_id, customer_name,
customer_street, customer_city )
loan = (loan_number, amount )
• Domain – the set of permitted values for each attribute
• Attribute types:
• Simple and composite attributes.
• Single-valued and multi-valued attributes
• Example: multivalued attribute: phone_numbers
• Derived attributes
• Can be computed from other attributes
• Example: age, given date_of_birth
Composite Attributes
Mapping Cardinality Constraints
• Express the number of entities to which another entity can be
associated via a relationship set.
• For a binary relationship set the mapping cardinality must be
one of the following types:
• One to one
• One to many
• Many to one
• Many to many
Mapping Cardinalities

One to one One to many

Note: Some elements in A and B may not be mapped to any elements in the other set
Mapping Cardinalities

Many to one Many to many

Note: Some elements in A and B may not be mapped to any elements in the other set
Keys
• A super key of an entity set is a set of one or more attributes
whose values uniquely determine each entity.
• A candidate key of an entity set is a minimal super key
• Customer_id is candidate key of customer
• account_number is candidate key of account
• Although several candidate keys may exist, one of the candidate
keys is selected to be the primary key.
Keys for Relationship Sets
• The combination of primary keys of the participating entity sets
forms a super key of a relationship set.
• (customer_id, account_number) is the super key of depositor
• Example: if we wish to track all access_dates to each account by each customer,
we cannot assume a relationship for each access. We can use a multivalued
attribute though
• Need to consider semantics of relationship set in selecting the
primary key in case of more than one candidate key
E-R Diagrams

n Rectangles represent entity sets.


n Diamonds represent relationship sets.
n Lines link attributes to entity sets and entity sets to relationship sets.
n Ellipses represent attributes
l Double ellipses represent multivalued attributes.
l Dashed ellipses denote derived attributes.
n Underline indicates primary key attributes
E-R Diagram With Composite, Multivalued, and Derived Attributes
Relationship Sets with Attributes
Roles
• Entity sets of a relationship need not be distinct
• The labels “manager” and “worker” are called roles; they specify how employee entities
interact via the works_for relationship set.
• Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to
rectangles.
• Role labels are optional, and are used to clarify semantics of the relationship
Cardinality Constraints
• 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.
• One-to-one relationship:
• A customer is associated with at most one loan via the relationship borrower
• A loan is associated with at most one customer via borrower
One-To-Many Relationship
• In the one-to-many relationship a loan is associated with at
most one customer via borrower, a customer is associated with
several (including 0) loans via borrower
Many-To-One Relationships
• In a many-to-one relationship a loan is associated with several
(including 0) customers via borrower, a customer is associated
with at most one loan via borrower
Many-To-Many Relationship
• A customer is associated with several (possibly 0) loans via
borrower
• A loan is associated with several (possibly 0) customers via
borrower
Participation of an Entity Set in a Relationship Set
n Total participation (indicated by double line): every entity in the entity set participates in at least one
relationship in the relationship set
l E.g. participation of loan in borrower is total
 every loan must have a customer associated to it via borrower
n Partial participation: some entities may not participate in any relationship in the relationship set
l Example: participation of customer in borrower is partial
E-R Diagram with a Ternary Relationship
Mapping Cardinalities affect ER Design
n Can make access-date an attribute of account, instead of a relationship attribute, if each account can have
only one customer
l That is, the relationship from account to customer is many to one, or equivalently, customer to account
is one to many
Weak Entity Sets
• An entity set that does not have a primary key is referred to as
a weak entity set.
• A weak entity is an entity that cannot be uniquely identified by
its attributes alone; therefore, it must use a foreign key in
conjunction with its attributes to create a primary key. The
foreign key is typically a primary key of an entity it is related to.
• The primary key of a weak entity set is formed by the primary
key of the strong entity set on which the weak entity set is
existence dependent, plus the weak entity set’s discriminator.
Weak Entity Sets (Cont.)
• We depict a weak entity set by double rectangles.
• We underline the discriminator of a weak entity set with a
dashed line.
• payment_number – discriminator of the payment entity set
• Primary key for payment – (loan_number, payment_number)
Specialization

Attribute inheritance – a lower-level


entity set inherits all the attributes and
relationship participation of the higher-
level entity set to which it is linked.
Extended ER Features: Generalization

• A bottom-up design process – combine a number of entity


sets that share the same features into a higher-level entity set.
• Specialization and generalization are simple inversions of each
other; they are represented in an E-R diagram in the same
way.
• The terms specialization and generalization are used
interchangeably.
E-R Diagram for a Banking Enterprise

You might also like