0% found this document useful (0 votes)
42 views

CH05 Er

The document provides an overview of entity-relationship (E-R) modeling and E-R diagrams. It defines key concepts such as entities, attributes, relationships, and keys. Entities are represented as rectangles, attributes as ovals, and relationships as diamonds in E-R diagrams. Relationships can be one-to-one, one-to-many, or many-to-many. Keys uniquely identify entities and are underlined in diagrams. Weak entity sets require a relationship to another entity set for unique identification. E-R diagrams allow conceptual modeling of databases prior to implementation.

Uploaded by

Hend Talafha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

CH05 Er

The document provides an overview of entity-relationship (E-R) modeling and E-R diagrams. It defines key concepts such as entities, attributes, relationships, and keys. Entities are represented as rectangles, attributes as ovals, and relationships as diamonds in E-R diagrams. Relationships can be one-to-one, one-to-many, or many-to-many. Keys uniquely identify entities and are underlined in diagrams. Weak entity sets require a relationship to another entity set for unique identification. E-R diagrams allow conceptual modeling of databases prior to implementation.

Uploaded by

Hend Talafha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 60

Entity-Relationship Model

1
E-R Diagrams

1
Purpose of E/R Model
 The E/R model allows us to sketch the
design of a database informally.
 Designs are pictures called entity-
relationship diagrams.
 Fairly mechanical ways to convert E/R
diagrams to real implementations like
relational databases exist.

2
Entity Sets
 Entity = “thing” or object.
 Entity set = collection of similar entities.
 Attribute = property of an entity set.
 Generally, all entities in a set have the same
properties.
 Attributes are simple values, e.g. integers or
character strings.

3
E/R Diagrams
 In an entity-relationship diagram, each
entity set is represented by a rectangle.
 Each attribute of an entity set is
represented by an oval, with a line to
the rectangle representing its entity set.

4
Example name Adviser

Student

 Entity set Student has two attributes, name


and Adviser.
 Each Student entity has values for these two
attributes, e.g. (Ahmad, Kazem)
5
Relationships
 A relationship connects two or more
entity sets.
 It is represented by a diamond, with
lines to each of the entity sets involved.

6
Example
name addr name code

Teachers teaches Courses - Teachers are


teaching some
courses.
Number
- Students take
Advises Takes some courses.

- Teachers advises
some students.
name Students addr
7
Relationship Set
 The current “value” of an entity set is
the set of entities that belong to it.
 Example: the set of all students in our
database.
 The “value” of a relationship is a set of
lists of currently related entities, one
from each of the related entity sets.

8
Example
 For the relationship Teaches, we might
have a relationship set like:

Teachers Courses
Ahmad C++
Samir Math
Ahmad Java
Amer Internet
Samir Algorithms
Jaber Math
Ramez C++ 9
Multiway Relationships
 Sometimes, we need a relationship that
connects more than two entity sets.
 Suppose that students will only take certain
courses taught by certain teachers.
 Our three binary relationships teaches, advises, and
takes do not allow us to make this distinction.
 But a 3-way relationship would.

10
Example
name addr name code

number Teachers Courses

Preferences

Students
name addr
11
A Typical Relationship Set

Teacher Student Course


Ahmad Issam C++
Ahmad Nour C++
Ahmad Nour Java
Amer Issam Internet
Samir Samar Math
Samir Issam Math
Samir Nader Algorithms

12
Many-Many Relationships
 Think of a relationship between two
entity sets, such as Teaches between
Teachers and Courses.
 In a many-many relationship, an entity
of either set can be connected to many
entities of the other set.
 E.g., a teacher teaches many courses; a
course is taught by many teachers.
13
In Pictures:

many-many

14
* Example of Many-Many Relationship
A customer is associated with several (possibly 0) loans
via borrower
A loan is associated with several (possibly 0) customers
via borrower

15
Many-One Relationships
 Some binary relationships are many -
one from one entity set to another.
 Each entity of the first set is connected
to at most one entity of the second set.
 But an entity of the second set can be
connected to zero, one, or many
entities of the first set.

16
In Pictures:

many-one

17
Example
 Advises, from Teachers to Students is
One-Many.
 A student has at most one adviser.
 But a teacher can be the adviser of any
number of students, including zero.

18
* Example of Many-One relationship
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

19
One-One Relationships
 In a one-one relationship, each entity of
either entity set is related to at most one
entity of the other set.
 Example: Relationship Is-in between entity
sets Teachers and Offices.
 A teacher cannot be in more than one office,
and no office can have more than one teacher
(assume this).
20
In Pictures:

one-one

21
* Example of One-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

22
Representing “Multiplicity”
 Show a many-one relationship by an
arrow entering the “one” side.
 Show a one-one relationship by arrows
entering both entity sets.

23
Example

Students Likes Courses

Favorite

24
Attributes on Relationships
 Sometimes it is useful to attach an
attribute to a relationship.
 Think of this attribute as a property of
tuples in the relationship set.

25
Example

Students Takes Course

Date

Date is a function of both the student and the


course, not of one alone.
26
Roles////
 Sometimes an entity set appears more
than once in a relationship.
 Label the edges between the
relationship and the entity set with
names called roles.

27
Example
Relationship Set

Husband Wife
Bob Ann
Joe Sue
Married
… …

husband wife
Teachers

28
Keys
 A key is a set of attributes for one
entity set such that no two entities in
this set agree on all the attributes of
the key.
 It is allowed for two entities to agree on
some, but not all, of the key attributes.
 We must designate a key for every
entity set.
29
Keys in E/R Diagrams
 Underline the key attribute(s).

30
Example: a Multi-attribute Key

dept number hours room

Courses

• Note that hours and room could also serve as a


key, but we must select only one key.

31
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. Other
candidate keys are alternate keys.
Weak Entity Sets
 Occasionally, entities of an entity set
need “help” to identify them uniquely.
 Entity set E is said to be weak if in
order to identify entities of E uniquely,
we need to follow one or more many-
one relationships from E and include
the key of the related entities from the
connected entity sets.
33
Example
 name is almost a key for football players, but
there might be two with the same name.
 number is certainly not a key, since players
on two teams could have the same number.
 But number, together with the Team related
to the player by Plays-on should be unique.

34
In E/R Diagrams
name number
-------- name

Players Plays- Teams


on

• Double diamond for supporting many-one relationship.


• Double rectangle for the weak entity set.

35
Weak Entity-Set Rules
 A weak entity set has one or more many-one
relationships to other (supporting) entity sets.
 Not every many-one relationship from a weak
entity set need be supporting.
 The key for a weak entity set is its own
underlined attributes and the keys for the
supporting entity sets.
 E.g., player-number and team-name is a key for
Players in the previous example.

36
Weak Entity-Set (Cont.)
 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
 it must relate to the identifying entity set via a total, one-
to-many relationship set from the identifying to the weak
entity set
 Identifying relationship depicted using a double diamond
 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.
Weak Entity Sets (Cont.)
 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
Weak Entity Sets (Cont.)
 We depict a weak entity set by double rectangles.
 We underline the discriminator of a weak entity set with a
dashed line.
 payment-number – discriminator of the payment entity set

 Primary key for payment – (loan-


number, payment-number)
Some types of attributes -
Composite
 Composite attribute is an attribute that
is composed of several attributes

40
Some types of attributes -
Multivalued
 Multivalued attribute is an attribute that
can have more than one value at a time

41
Some types of attributes -
Derived
 Derived attribute is an attribute whose
value is calculated (derived) from
other attributes

42
Enhanced Entity-Relationship
Model

43
Enhanced-ER (EER) Model
Concepts
 Includes all modeling concepts of basic ER.
 Additional concepts: subclasses/super classes,
specialization/generalization, categories, attribute
inheritance.
 The resulting model is called the enhanced-ER or
Extended ER (E2R or EER) model.
 It is used to model applications more completely and
accurately if needed.
 It includes some object-oriented concepts, such as
inheritance.

44
Subclasses and Super classes
(1)
 An entity type may have additional meaningful sub
groupings of its entities.
 Example: EMPLOYEE may be further grouped into
SECRETARY, ENGINEER, MANAGER, TECHNICIAN,
SALARIED_EMPLOYEE, HOURLY_EMPLOYEE,…
 Each of these groupings is a subset of EMPLOYEE entities.
 Each is called a subclass of EMPLOYEE.
 EMPLOYEE is the superclass for each of these subclasses.
 These are called superclass/subclass relationships.
 Example: EMPLOYEE/SECRETARY,
EMPLOYEE/TECHNICIAN.

45
Subclasses and Super classes
(2)
 These are also called IS-A relationships (SECRETARY IS-A
EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, …).
 Note: An entity that is member of a subclass represents the
same real-world entity as some member of the super class.
 The Subclass member is the same entity in a distinct specific
role.
 An entity cannot exist in the database merely by being a
member of a subclass; it must also be a member of the
super class.
 A member of the super class can be optionally included as a
member of any number of its subclasses.
 Example: A salaried employee who is also an engineer belongs
to the two subclasses ENGINEER and SALARIED_EMPLOYEE.
 It is not necessary that every entity in a super class be a
member of some subclass.
46
Attribute Inheritance
 An entity that is member of a
subclass inherits all attributes of the
entity as a member of the super
class.
 It also inherits all relationships.
Specialization
 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.
 Is the process of defining a set of subclasses of a
super class.
 The set of subclasses is based upon some
distinguishing characteristics of the entities in the
super class.

48
Specialization
 Example: {SECRETARY, ENGINEER, TECHNICIAN} is a
specialization of EMPLOYEE based upon job type.
 May have several specializations of the same super class.
 Example: Another specialization of EMPLOYEE based in
method of pay is {SALARIED_EMPLOYEE,
HOURLY_EMPLOYEE}.
 Super class/subclass relationships and specialization can
be diagrammatically represented in EER diagrams.
 Attributes of a subclass are called specific attributes. For
example, TypingSpeed of SECRETARY.
 The subclass can participate in specific relationship
types. For example, BELONGS_TO of
HOURLY_EMPLOYEE.

49
Example of a Specialization

50
Generalization
 The reverse of the specialization process.
 Several classes with common features are generalized into a
super class; original classes become its subclasses.
 Example: CAR, TRUCK generalized into VEHICLE; both CAR,
TRUCK become subclasses of the super class VEHICLE.
 We can view {CAR, TRUCK} as a specialization of
VEHICLE.
 Alternatively, we can view VEHICLE as a generalization of
CAR and TRUCK.

51
Generalization and Specialization
 Data Modeling with Specialization and Generalization
 A super class or subclass represents a set of
entities.
 Shown in rectangles in EER diagrams (as are
entity types).
 Sometimes, all entity sets are simply called
classes, whether they are entity types, super
classes, or subclasses.

52
Constraints on Specialization and
Generalization
 Two other conditions apply to a
specialization/generalization:
 Disjointness Constraint:
 Specifies that the subclasses of the specialization must be
disjointed (an entity can be a member of at most one of the
subclasses of the specialization).
 Specified by d in EER diagram.
 If not disjointed, overlap; that is the same entity may be a member
of more than one subclass of the specialization.
 Specified by o in EER diagram.
 Completeness Constraint:
 Total specifies that every entity in the super class must be a
member of some subclass in the specialization/ generalization.
 Shown in EER diagrams by a double line.
 Partial allows an entity not to belong to any of the subclasses.
 Shown in EER diagrams by a single line.
Constraints on Specialization and
Generalization
 Hence, we have four types of
specialization/generalization:
 Disjoint, total
 Disjoint, partial
 Overlapping, total
 Overlapping, partial
 Note: Generalization usually is total because the
super class is derived from the subclasses.
Example of Partial-Disjoint
Specialization
Example of Total-Overlap
Specialization

56
Summary of Symbols Used in
E-R Notation

57
Summary of Symbols (Cont.)

58
Alternative E-R Notations

59
END

60

You might also like