L3 ERelational Model
L3 ERelational Model
L3 ERelational Model
Chapter-2
11/4/2022 3
Attributes
An entity is represented by a set of attributes, that is descriptive
properties possessed by all members of an entity set.
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: multi valued attribute: phone_numbers
Derived attributes
Can be computed from other attributes
Example: age, given date_of_birth
11/4/2022 4
Composite Attributes
11/4/2022 5
Relationship Sets
A relationship is an association among several entities
Example:
Hayes depositor A-102
customer entity relationship set account entity
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}
11/4/2022 6
Relationship Set borrower
customer_id customer_ customer_ customer_ loan_ amount
name street city number
11/4/2022 7
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
11/4/2022 8
Degree of a Relationship Set
11/4/2022 9
Mapping Cardinality Constraints
Number of entities to which another entity can be
associated via a relationship set.
Most useful in describing binary relationship sets.
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
11/4/2022 10
Mapping Cardinalities
11/4/2022 13
Keys for Relationship Sets
• The combination of primary keys of the participating entity sets
form a super key of a relationship set.
Example:
11/4/2022 14
Entity-Relationship Model
▪ An entity relationship diagram (ERD) is a representation
of data within a domain.
▪ It consists of entities as well as relationships between
entities.
▪ A graphical representation of entities and their
relationships to each other
▪ A logical data model of the real world.
11/4/2022 15
E-R Diagrams
Age
Derived
Attribute
11/4/2022 17
E-R Diagram With Composite, Multivalued, and Derived
Attributes
11/4/2022 18
Relationship Sets with Attributes
11/4/2022 19
Summary of Symbols Used in E-R Notation
11/4/2022 20
Roles
• The function that an entity plays in a relationship is called role.
• 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
11/4/2022 21
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
11/4/2022 22
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
11/4/2022 23
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
11/4/2022 24
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
11/4/2022 25
Participation of an Entity Set in a Relationship Set
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
Partial participation: some entities may not participate in any
relationship in the relationship set
Example: participation of customer in borrower is partial
11/4/2022 26
Participation of an Entity Set in a Relationship Set
11/4/2022 27
Alternative Notation for Cardinality Limits
• Cardinality limits can also express participation
constraints
11/4/2022 28
E-R Diagram with a Ternary Relationship
11/4/2022 29
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
weak entity set relate to the identifying entity set via a total, one-to-many
relationship
Identifying relationship depicted using a double diamond
11/4/2022 30
Weak Entity Sets
The discriminator (or partial key) of a weak entity set is the set of
attributes that distinguishes among all the entities of a weak entity
set.
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.
11/4/2022 31
Weak Entity Sets
We depict a weak entity set by double rectangles.
We underline the discriminator of a weak entity set with a
dashed line.
Primary key for payment – (loan_number, payment_number)
11/4/2022 32
Extended E-R Features: Specialization
Top-down design process; we designate sub groupings within an entity
set that are distinctive from other entities in the set.
11/4/2022 33
Specialization
• A group of entities is divided into sub-groups based on their
characteristics
11/4/2022 34
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.
• The ISA relationship also referred to as superclass -
subclass relationship
11/4/2022 35
Generalization
• Process of generalizing entities. The generalized entities contain the
properties of all the generalized entities called generalization
11/4/2022 36
Specialization/Generalization Example
11/4/2022 37
Specialization/Generalization Example
11/4/2022 38
Design Constraints on a Specialization/Generalization
Constraint on which entities can be members of a given lower-level
entity set.
condition-defined
Example: all customers over 65 years are members of senior-
citizen entity set; senior-citizen ISA person.
user-defined
Constraint on whether or not entities may belong to more than one
lower-level entity set within a single generalization.
Disjoint
an entity can belong to only one lower-level entity set
Noted in E-R diagram by writing disjoint next to the ISA triangle
Overlapping
an entity can belong to more than one lower-level entity set
11/4/2022 39
Design Constraints on a Specialization/Generalization
(Cont.)
• Completeness constraint -- specifies whether or not an entity in the
higher-level entity set must belong to at least one of the lower-level entity
sets within a generalization.
• total : an entity must belong to one of the lower-level entity sets
• partial: an entity need not belong to one of the lower-level entity sets
11/4/2022 40
Aggregation
Suppose we want to record managers for tasks
performed by an employee at a branch
11/4/2022 41
Aggregation (Cont.)
Relationship sets works_on and manages represent overlapping
information
Every manages relationship corresponds to a works_on relationship
However, some works_on relationships may not correspond to any manages
relationships
So we can’t discard the works_on relationship
Eliminate this redundancy via aggregation
Treat relationship as an abstract entity
Allows relationships between relationships
Abstraction of relationship into new entity
Without introducing redundancy
An employee works on a particular job at a particular branch
An employee, branch, job combination may have an associated manager
11/4/2022 42
E-R Diagram With Aggregation
11/4/2022 43
E-R Diagram With Aggregation
Defines a new relationship which associates some entity with some other existing
relationship called aggregation.
11/4/2022 44
Reduction to Relation Schemas
An E-R diagram can be represented by a collection of schemas.
Primary keys allow entity sets and relationship sets to be expressed
uniformly as relation schemas.
For each entity set and relationship set there is a unique schema
that is assigned the name of the corresponding entity set or
relationship set.
Each schema has a number of columns (generally corresponding to
attributes), which have unique names.
11/4/2022 45
Representing Entity Sets as Schemas
A strong entity set reduces to a schema with the same attributes.
A weak entity set becomes a table that includes a column for the primary
key of the identifying strong entity set
loan(loan_number, amount)
payment = ( loan_number, payment_number, payment_date,
payment_amount )
Representing Relationship Sets as Schemas
11/4/2022 48
Redundancy of Schemas (Cont.)
For one-to-one relationship sets, either side can be
chosen to act as the “many” side
11/4/2022 49
Binary Vs. Non-Binary Relationships
Some relationships that appear to be non-binary may be better
represented using binary relationships
E.g. A ternary relationship parents, relating a child to his/her father and
mother, is best replaced by two binary relationships, father and mother
Using two binary relationships allows partial information (e.g. only mother being
know)
But there are some relationships that are naturally non-binary
Example: works_on
11/4/2022 50
Converting Non-Binary Relationships to Binary Form
• In general, any non-binary relationship can
be represented using binary relationships
by creating an artificial entity set.
• Replace R between entity sets A, B and C by
an entity set E, and three relationship sets:
For each relationship (ai , bi , ci) in R,
1. RA, relating E and A create
2. RB, relating E and B 1. a new entity ei in the entity set E
3. RC, relating E and C 2. add (ei , ai ) to RA
• Create a special identifying attribute for E 3. add (ei , bi ) to RB
4. add (ei , ci ) to RC
• Add any attributes of R to E
11/4/2022 51
Binary vs. Ternary Relationships
name
ssn lot pname age
Bad design
Policies
policyid cost
Dependents
Employees
Purchaser
Beneficiary
Better design
Policies
policyid cost
11/4/2022 52
Transforming E-R Diagrams into Relations
11/4/2022 53
Transforming E-R Diagrams into Relations
1. Represent entities
11/4/2022 54
E-R Diagrams
11/4/2022 55
Transforming E-R Diagrams into Relations
2. Represent relationships
11/4/2022 56
Transforming E-R Diagrams into Relations
2. Represent relationships (cont.)
11/4/2022 57
Transforming E-R Diagrams into Relations
2. Represent relationships (cont.)
11/4/2022 58
Transforming E-R Diagrams into Relations
since
Key Constraints name dname
You can create a new table for the Or, no new table for relation but
relation Primary key foreign key relation
Only.
CREATE TABLE Manages(
CREATE TABLE Dept_Mgr(
ssn CHAR(11),
did INTEGER,
did INTEGER,
dname CHAR(20),
since DATE,
budget REAL,
PRIMARY KEY (did),
ssn CHAR(11),
FOREIGN KEY (ssn) REFERENCES
since DATE,
Employees,
PRIMARY KEY (did),
FOREIGN KEY (did) REFERENCES
FOREIGN KEY (ssn) REFERENCES
Departments)
Employees)
59
Transforming E-R Diagrams into Relations
Weak Entities
Weak entity set and identifying relationship set are translated into a single table.
When the owner entity is deleted, all owned weak entities must also be deleted.
name
cost pname age
ssn lot
11/4/2022 61
Thank You