ch2dbms (copy)
ch2dbms (copy)
Entity Sets
Relationship Sets
Mapping Constraints
Keys
E-R Diagram
Extended E-R Features
Design of an E-R Database Schema
Reduction of an E-R Schema to Tables
Entity-Relationship Model
2
Database requirements
• We must convert the written database
requirements into an E-R diagram
• Need to determine the entities, attributes and
relationships.
– nouns = entities
– adjectives = attributes
– verbs = relationships
3
The Pieces
• Objects
– Entity (including weak entities)
– Attribute
– Relationship
• “Structural” Constraints
– Cardinality
– Participation
4
Entities
• Entity – basic object of the E-R model
– Represents a “thing” with an independent
existence
– Can exist physically or conceptually
• a professor, a student, a course
• Entity type – used to define a set of entities
with the same properties.
5
Entity and Entity Types
Name
Number Topic
Entity Type
Course
Number: 3753
Name: Database Management
Entity Systems
Topic: Introduction to DBMSs
6
Attributes
• Each entity has a set of associated properties that
describes the entity. These properties are known as
attributes.
• Attributes can be:
– Simple or Composite
– Single or Multi-valued
– Stored or Derived
– NULL
7
Attributes (cont’d)
First
Professor Name
Composite
Last
8
Attributes (cont’d)
9
Attributes (cont’d)
10
Attributes(cont..)
Complex Attributes:
- collection of composite and multivalued
attributes.
- Eg. Address ,phone no.
11
Attributes (cont’d)
• NULL attributes have no value
– not 0 (zero)
– not a blank string
• Attributes can be “nullable” where a null value
is allowed, or “not nullable” where they must
have a value.
12
Primary Keys
Professor Employee ID
13
Relationships
• defines a set of associations between various
entities
• can have attributes to define them
• are limited by:
– Participation
– Cardinality Ratio
14
Relationships (cont’d)
15
Participation
• Defines if the existence of an entity depends on it
being related to another entity with a relationship
type.
• What is the minimum number of relationship in
which entity can participate.
– Total
- Partial
Emp Works-for Dept
16
Contd..
• Types of participation constraints:
17
Contd..
18
Concepts and Notations (cont)
Relationship
• A relationship R among n entity types E1,E2, ..
En defines a set of associations (relationship
set) among entities from these types.
• A relationship has its type and set (instances).
• Each instance in R is an association of entities,
where the association includes exactly one
entity from each participating entity type.
• The reference from entity to another should be
represented in the ER model as a relationship
not as attributes.
19
Constraints on Relationship Types
• Cardinality Ratio: it specifies the number of
relationship instances that an entity can
participate in.
• What is the maximum no. of relationship in
which an entity can participate.
EMPLOYEE r1
e1 •
PROJECT
e2 • r2
e3 •
• p1
e4 • r3 • p2
e5 • • p3
. .
r4 .
.
.
.
r5
23
Attributes of Relationship Types
• Relationship types can also have
attributes (e.g. “Works-On” may have
attributes as hours, start_date, ..etc).
24
Weak Entity Sets
An entity set that does not have a primary key
is referred to as a weak entity set.
An entity set that has a primary key is
referred to as a strong entity set.
E.g. Entiy set payment has 3 attributes:
- payment_number,payment_date,
payment_amount, payment for
different loans may share the same
payment number.
Weak Entity Sets...
Note: the primary key of the strong entity set is not
explicitly stored with the weak entity set, since it is
implicit in the identifying relationship.
If loan-number were explicitly stored, payment could
be made a strong entity, but then the relationship
between payment and loan would be duplicated by
an implicit relationship defined by the attribute loan-
number common to payment and loan
More Weak Entity Set Examples
In a university, a course is a strong entity and a course-offering
can be modeled as a weak entity
The discriminator of course-offering would be semester
(including year) and section-number (if there is more than one
section)
If we model course-offering as a strong entity we would model
course-number as an attribute.
Then the relationship with course would be implicit in the
course-number attribute
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
Roles...
Symbols Used in E-R Notation
Summary of Symbols (Cont.)
Alternative E-R Notations
Keys
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
Design Constraints on a
Specialization/Generalization (Contd.)
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
Aggregation
Consider the ternary relationship works-on, which we saw earlier
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.
Reduction of an E-R Schema to Tables...
If specialization is total, table for generalized entity (person) not
required to store information
Can be defined as a “view” relation containing union of
specialization tables
But explicit table may still be needed for foreign key
constraints
Drawback: street and city may be stored redundantly for persons
who are both customers and employees
Relations Corresponding to
Aggregation
Design an E-R schema for a database to store info about professors, courses
and course sections indicating the following:
• The name and employee ID number of each professor
• The salary and email address(es) for each professor
• How long each professor has been at the university
• The course sections each professor teaches
• The name, number and topic for each course offered
• The section and room number for each course section
• Each course section must have only one professor
• Each course can have multiple sections
76
Visual View of the Database
1 N
Professor teaches Section
Email
Salary First
Name Part of
Last
1
Number Course
77
Topic Name
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
E.g. works-on
End of Chapter 2
E-R Diagram for Exercise 2.10
E-R Diagram for Exercise 2.15
E-R Diagram for Exercise 2.22
E-R Diagram for Exercise 2.15
Existence Dependencies
If the existence of entity x depends on the existence of
entity y, then x is said to be existence dependent on y.
y is a dominant entity (in example below, loan)
x is a subordinate entity (in example below, payment)
Contd..