Database System Concept: by Silberschatz, Korth and Sudarshan
Database System Concept: by Silberschatz, Korth and Sudarshan
26-Feb-19 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 )
26-Feb-19 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}
26-Feb-19 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
26-Feb-19 8
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.
26-Feb-19 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
26-Feb-19 10
Mapping Cardinalities
26-Feb-19 13
Keys for Relationship Sets
• The combination of primary keys of the participating entity sets
form a super key of a relationship set.
Example:
26-Feb-19 15
E-R Diagrams
26-Feb-19 18
Relationship Sets with Attributes
26-Feb-19 19
Summary of Symbols Used in E-R Notation
26-Feb-19 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
26-Feb-19 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
26-Feb-19 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
26-Feb-19 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
26-Feb-19 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
26-Feb-19 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
26-Feb-19 26
Participation of an Entity Set in a Relationship Set
26-Feb-19 28
E-R Diagram with a Ternary Relationship
26-Feb-19 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
26-Feb-19 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.
26-Feb-19 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)
26-Feb-19 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.
26-Feb-19 33
Specialization
• A group of entities is divided into sub-groups based on their
characteristics
26-Feb-19 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 26-Feb-19 35
Generalization
• Process of generalizing entities. The generalized entities
contain the properties of all the generalized entities called
generalization
26-Feb-19 36
Specialization/Generalization
Example
26-Feb-19 37
Specialization/Generalization
Example
26-Feb-19 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
26-Feb-19 39
an entity can belong to more than one lower-level entity set
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
26-Feb-19 40
Aggregation
● Suppose
we want to record managers for tasks
performed by an employee at a branch
26-Feb-19 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
26-Feb-19 42
E-R Diagram With Aggregation
26-Feb-19 43
E-R Diagram With Aggregation
Defines a new relationship which associates some entity with some other existing
relationship called aggregation.
26-Feb-19 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.
26-Feb-19 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
26-Feb-19 48
Redundancy of Schemas (Cont.)
⚫ For one-to-one relationship sets, either side can be chosen
to act as the “many” side
26-Feb-19 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
26-Feb-19 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:
1. RA, relating E and A
2.RB, relating E and B
3. RC, relating E and C
• Create a special identifying attribute for E
• Add any attributes of R to E
• For each relationship (ai , bi , ci) in R, create
1. a new entity ei in the entity set E 2. add (ei , ai ) to RA
3. add (ei , bi ) to RB 4. add (ei , ci ) to RC
26-Feb-19 51
Binary vs. Ternary Relationships
name
ssn lot pname age
Bad design
Policies
policyid cost
Dependents
Employees
Purchaser
Beneficiary
Better design
Policies
policyid cost
26-Feb-19 52
Transforming E-R Diagrams into Relations
26-Feb-19 53
Transforming E-R Diagrams into Relations
26-Feb-19 55
Transforming E-R Diagrams into Relations
26-Feb-19 56
Transforming E-R Diagrams into Relations
26-Feb-19 57
Transforming E-R Diagrams into Relations
Represent Relationships (continued)
• Binary and higher M:N relationships
• Create another relation and include primary keys of all relations as
primary key of new relation
26-Feb-19 58
Key Constraints
• Each dept has at most
one manager, according since
to the key constraint on name dname
Manages.
ssn lot did budget
CREATE TABLE Manages(
ssn CHAR(11),
did INTEGER, Employees Manages Departments
since DATE,
PRIMARY KEY (did), CREATE TABLE Dept_Mgr(
FOREIGN KEY (ssn) REFERENCES did INTEGER,
Employees, dname CHAR(20),
FOREIGN KEY (did) REFERENCES budget REAL,
Departments) ssn CHAR(11),
You can create single table for the since DATE,
relatin or no new table for relation but PRIMARY KEY (did),
Primary key foreign key relation FOREIGN KEY (ssn) REFERENCES
Only. Employees)
59
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
26-Feb-19 61
Thank You