2. An entity-relationship (ER) diagram is a specialized
graphic that illustrates the interrelationships
between entities in a database.
ER diagrams often use symbols to represent three
different types of information, namely, entities,
attributes and relationships.
Entity-Relationship Model
3. Define Entities: These are usually nouns used in
descriptions of the system, in the discussion of business
rules, or in documentation; identified in the narrative.
Define Relationships: These are usually verbs used in
descriptions of the system or in discussion of the
business rules (entity entity); identified in the
narrative.
Add attributes to the relations: These are determined by
the queries, and may also suggest new entities, e.g.
grade; or they may suggest the need for keys or
identifiers.
How do we start ERD
4. Entity
An entity is an object or concept about which you want to store
information.
Key attribute
A key attribute is the unique, distinguishing characteristic of the
entity. For example, an employee's social security number might
be the employee's key attribute.
ER Diagram Symbols
5. Relationships
Relationships illustrate how two entities share information in the
database structure.
Weak Entity
A weak entity is an entity that must defined by a foreign key
relationship with another entity as it cannot be uniquely identified
by its own attributes alone.
ER Diagram Symbols
6. Derived attribute
A derived attribute is based on another attribute. For example, an
employee's monthly salary is based on the employee's annual
salary.
Multivalued attribute
A multivalued attribute can have more than one value. For
example, an employee entity can have multiple skill values.
ER Diagram Symbols
7. Cardinality specifies how many instances of an entity relate to one instance
of another entity.
Ordinality is also closely linked to cardinality.
While cardinality specifies the occurrences of a relationship, ordinality
describes the relationship as either mandatory or optional.
In other words, cardinality specifies the maximum number of relationships
and ordinality specifies the absolute minimum number of relationships.
When the minimum number is zero, the relationship is usually called
optional and when the minimum number is one or more, the relationship is
usually called mandatory.
How to express Relationships
9. *Example of schema in the entity- relationship model
Entity-Relationship Model
10. E-R model of real world
◦ Entities (objects)
E.g. customers, accounts, bank branch
◦ Relationships between entities
E.g. Account A-101 is held by customer Johnson
Relationship set depositor associates customers with
accounts
Widely used for database design
◦ Database design in E-R model usually converted to
design in the relational model (coming up next) which is
used for storage and processing
Entity Relationship Model (Cont.)
11. Specification notation for defining the database
schema
◦ E.g.
create table account (
account-number char(10),
balance integer)
DDL compiler generates a set of tables stored in
a data dictionary
Data dictionary contains metadata (i.e., data
about data)
Data Definition Language (DDL)
12. 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
Entity Sets
13. Entity Sets ‘customer ‘ and ‘loan’
customer-id amount
customer- customer- customer-
name street city
loan-
number
14. Express the 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
Mapping Cardinalities
15. 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
16. 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
17. 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
n I.e., the relationship from account to customer is many to one,
or equivalently, customer to account is one to many
18. 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
n Double ellipses represent multivalued attributes.
n Dashed ellipses denote derived attributes.
n Underline indicates primary key attributes (will study later)
21. 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.
E.g.: 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
Cardinality Constraints
22. 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
One-To-Many Relationship
23. In a many-to-one relationship a loan is
associated with several customers via borrower,
a customer is associated with at most one loan
via borrower
Many-To-One Relationships
24. A customer is associated with several (possibly
0) loans via borrower
A loan is associated with several customers via
borrower
Many-To-Many Relationship
26. Top-down design process; we designate sub groupings
within an entity set that are distinctive from other entities
in the set.
These sub groupings become lower-level entity sets that
have attributes or participate in relationships that do not
apply to the higher-level entity set.
Depicted by a triangle component labeled IS A (E.g.
customer “is a” person).
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.
Specialization
28. 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.
Generalization
30. Generalization (Cont..)
Generalization suppresses the difference among
several entity types, identifying their common
features, and generalize them into a single
superclass of which the original types are special
subclasses.
The decision as to which process, generalization
or specialization, is more appropriate in a
particular situation is often subjective.
31. Can have multiple specializations of an entity set based on
different features.
E.g. permanent-employee vs. temporary-employee, in
addition to officer Vs secretary Vs teller
Each particular employee would be
◦ a member of one of permanent-employee or temporary-
employee,
◦ and also a member of one of officer, secretary, or teller
The IS A relationship also referred to as superclass - subclass
relationship
Specialization and Generalization
32. The use of an attribute or entity set to represent an
object.
Whether a real-world concept is best expressed by an
entity set or a relationship set.
The use of a ternary relationship versus a pair of binary
relationships.
The use of a strong or weak entity set.
The use of specialization/generalization – contributes to
modularity in the design.
The use of aggregation – can treat the aggregate entity
set as a single unit without concern for the details of its
internal structure.
E-R Design Decisions
35. Primary keys allow entity sets and relationship sets to be
expressed uniformly as tables which represent the contents
of the database.
A database which conforms to an E-R diagram can be
represented by a collection of tables.
For each entity set and relationship set there is a unique table
which is assigned the name of the corresponding entity set or
relationship set.
Each table has a number of columns (generally corresponding
to attributes), which have unique names.
Converting an E-R diagram to a table format is the basis for
deriving a relational database design from an E-R diagram.
Reduction of an E-R Schema to Tables
36. A strong entity set reduces to a table with the
same attributes.
Representing Entity Sets as Tables