Data Modeling Using Entity Relationship Model

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

Data Modeling using Entity

Relationship Model
Entity sets
• A database can be modeled as:
▫ a collection of entities,
▫ relationship among entities.
• An entity is a thing in the real world with an
independent existence.
• An entity may be an object with a physical existence (for
example, a particular person, car, house, or employee) or
it may be an object with a conceptual existence (for
instance, a company, a job, or a university course).
• 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
Entities- Employee and
Company
Attributes
• An entity is represented by a set of attributes, that is
descriptive properties possessed by all members of an
entity set.
• Domain – the set of permitted values for each attribute
• Example:
customer = (customer-id, customer-name, customer-
street, customer-city)
loan = (loan-number, amount)
• Attribute types:
▫ Simple and composite attributes.
▫ Single-valued and multi-valued attributes
 E.g. multivalued attribute: phone-numbers
▫ Derived attributes
 Can be computed from other attributes
 E.g. age, given date of birth
Example of Composite
attributes
Relationships
• A relationship is an association among several
entities
• Degree of relationship 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.
Ternary Relationship Examples
Cardinalities
• Cardinality 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
a) One to One
b) One to Many
Mapping Cardinalities
c) Many to One
d) Many to Many
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.
• The other candidate keys are said to be Secondary key.
• 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
Entity Relationship Diagram
• Rectangles represent entity sets.
• Diamonds represent relationship sets.
• Lines link attributes to entity sets and entity sets to relationship
sets.
• Ellipses represent attributes
• Double ellipses represent multivalued attributes.
• Dashed ellipses denote derived attributes.
• Underline indicates primary key attributes
Entity Car
Entity Employee
Entity Department
An Entity Example
Role Names and Recursive
Relationship
• The role name signifies the role that a
participating entity from the entity type
plays in each relationship, and helps to
explain what the relationship means.
• For example, in the WORKS_FOR
relationship type, EMPLOYEE plays the
role of employee or worker and
DEPARTMENT plays the role of
department or employer.
Participation of Entity Set in
Relationship
• Total participation (indicated by double line): every
entity in the entity set participates in at least one
relationship in the relationship set
▫ E.g. participation of loan in borrower is total
▫ every loan must have a customer associated to it via borrower
• Partial participation: some entities may not participate in
any relationship in the relationship set
▫ E.g. participation of customer in borrower is partial
Weak Entity Sets
• 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 a identifying entity set.
▫ Identifying relationship depicted using a double
diamond.
• 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(partial key of weak entity).
• We depict a weak entity set by double rectangles.
• We underline the discriminator of a weak entity set
with a dashed line.
Weak Entity Sets
ER-diagram for Car-insurance
company
Specialization and
Generalization
• Specialization- Top-down design process; we
designate subgroupings within an entity set that
are distinctive from other entities in the set.
• Generalization- A bottom-up design process;
combine a number of entity sets that share the
same features into a higher-level entity set.
• Depicted by a triangle component labeled ISA
(E.g. customer “is a” person).
• Specialization and generalization are simple
inversions of each other; they are represented in
an E-R diagram in the same way.
ER-diagram for motor-vehicle sales
company
ER-diagram for Movies database
Question
Suppose you are given the following requirements for a
database for the National Hockey League (NHL). The NHL has
many teams.
• Each team has a name, a city, a coach, a captain and a set of
players.
• Each player belongs to only one team.
• Each player has a name, a position (such as left wing or
goalie), a skill level, and a set of injury records.
• Each team has a team captain, a team captain is also a player.
• Injury record of each player is kept with its description
(injury-date, injury-type).
• A game is played between two teams, referred to as Host
team and Guest team and has a date and a score.
Draw the Entity Relationship diagram for the above scenario.
ER Diagram

You might also like