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

Chapter 3-Data Modelling Using Entity Relationship Model

it describes about Data Model Basic Building Blocks in Using High level Data Models for Database Design Entity types and Sets, Attributes and Keys, Relationships, Roles and Structural Constraints, Enhanced ER Diagram, E-R mapping to Relational Database model.

Uploaded by

Misganaw Abeje
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Chapter 3-Data Modelling Using Entity Relationship Model

it describes about Data Model Basic Building Blocks in Using High level Data Models for Database Design Entity types and Sets, Attributes and Keys, Relationships, Roles and Structural Constraints, Enhanced ER Diagram, E-R mapping to Relational Database model.

Uploaded by

Misganaw Abeje
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Fundamentals of Database

system

Chapter Three:
Data Modelling using
Entity Relationship Model
Prepared by:
Misganaw Abeje
University of Gondar
College Of Informatics
Department of computer science
[email protected]
Outline

 Data Model Basic Building Blocks


 Using High level Data Models for Database Design
 Entity types and Sets, Attributes and Keys
 Relationships, Roles and Structural Constraints
 Weak Entity Types
 Enhanced ER Diagram
 E/R mapping to Relational

BY: MA
Data Model Basic Building Blocks

 To design a database first we have to understand the


basic Building block of relational Data model.
 Entity: anything about which data are to be collected and
stored
 Attribute: a characteristic of an entity
 Relationship: describes an association
among entities
– One-to-many (1:M) relationship
– Many-to-many (M:N or M:M) relationship
– One-to-one (1:1) relationship
• Constraint: a restriction placed on the data
BY: MA
Business Rules

 Descriptions of policies, procedures, or principles within


a specific organization
– Apply to any organization that stores and uses data to
generate information
 Description of operations to create/enforce actions
within an organization’s environment.
 Must be in writing and kept up to date.
 Must be easy to understand and widely disseminated.
 Describe characteristics of data as viewed by the
company.
BY: MA
Discovering Business Rules

 Sources of business rules:


– Company managers
– Policy makers
– Department managers
– Written documentation
 Procedures
 Standards
 Operations manuals
– Direct interviews with end users

BY: MA
Cont…

 Standardize company’s view of data


 Communications tool between users and designers
 Allow designer to understand the nature, role, and
scope of data.
 Allow designer to understand business processes
 Allow designer to develop appropriate relationship
participation rules and constraints .

BY: MA
Translating Business Rules into
Data Model Components

Generally:
 nouns translate into entities
 Verbs translate into relationships among entities.
 possessive phrases or description of refers to
attribute of entities.
 Relationships are bidirectional.
 Two questions to identify the relationship type:
– How many instances of B are related to one
instance of A?
– How many instances of A are related to one
instance of B?
BY: MA
Using High level Data Models for Database Design

 High-level conceptual data models provide concepts


for presenting data in ways that are close to the way
people perceive data.
 A typical example is the entity relationship model, which
uses main concepts like entities, attributes and
relationships.
 The two common conceptual models for Relational
Database system are
– Entity – Relationship (E/R) model
– Object-Oriented Data Language (ODL) model

BY: MA
Entity – Relationship (E/R) Data Model

 The E/R data model views the real world as a


set of
– Basic objects (Entities), and
– Relationships among these objects.
 The three basic notions of the E/R model are:
– Entity
– Relationship
– Attribute

BY: MA
Cont…

 Entities are usually recognizable concepts, either


concrete or abstract, such as:
– person, places, things, or events which have
relevance to the database.
 An Entity Set is then a set consisting of the same
type of entities that share same properties.
 In the requirement analysis the entities are
recognized by nouns and noun phrases.

BY: MA
Cont…

 Entities can be classified as:


– Strong (independent) entity
 One that does not rely on other entities for identification.
– Weak (dependent) entity
 one that relies on other entities for identification.
 Instance
– Instance also known as Object is an individual
occurrence of an entity set.

BY: MA
Attributes

 Attributes are descriptive properties that are


associated with an entity.
 Value
– Value is a particular instance of an attribute.
 Domain
– The domain of an attribute is the collection of all
possible values an attribute can have.

BY: MA
Classification of Attributes

 Identifiers
– more commonly called keys, uniquely identify an
instance of an entity.
 Descriptor
– describes a non-unique characteristic of an entity
instance.
 Example
– furniture Id
– catalog number, model type, color, …
13
BY: MA
… Classification of Attributes

 Simple Attributes
– also known as Atomic Attributes that can not be divided
into subparts mainly of primitive types.
 Composite Attributes
– are composed of smaller subparts that can be further
subdivided into the subparts (Attributes).
 Example
– Id, type, price, color
– name, address

14
BY: MA
… Classification of Attributes

 Single-valued Attributes
– are attributes having only one possible value at any
time.
 Multi-valued Attributes
– are attributes that are having possibly more than one
value.
 Example
– Id, name, type, price
– Address, degree
15
BY: MA
… Classification of Attributes

 Derived Attributes
– are attributes that can be calculated from the related
stored attributes, entities or general states.
 Stored Attributes
– are attributes that can not be calculated in any way
from the stored attributes.
 Example
– Age
– Birth Date
16
BY: MA
Relationship Sets

 A Relationship represents an association between


two or more entities.
 Example
– FURNITURE is produced by an EMPLOYEE from
RESOURCE
 FURNITURE is produced by EMPLOYEE
 FURNITURE is produced from RESOURCE
 SALE of FURNITURE is made with RECEIPT

17
BY: MA
… Relationship Sets
 A Relationship Set is then a set consisting same types of relationships. A
relationship should be named by a Verb or phrase which explains its
function (role name)
 Classification terms in Relationships
1. Degree
– number of entities associated with the relationship
 Binary – links two entity sets; set of ordered pairs (most common)
E.g. STUDENT and DORMITORY || STUDENT and COURSE
– Ternary – links three entity sets; ordered triples (rare). If a
relationship exists among the three entities, all three must be present.
E.g. INSTRUCTOR ,STUDENTS and a particular COURSE
 N-ary – links n entity sets; ordered n-tuples (extremely rare). If a
relationship exists among the entities, then all must be present. E.g.
18 INSTRUCTOR ,STUDENTS, rooms and a particular COURSE
BY: MA
… Relationship Sets
 Cardinality
– the actual number of related occurrences for each of the two entities
– is the number of entity instances to which another entity set can
map under the relationship.
 One-to-one: X-Y is 1:1 when each entity in X is associated
with at most one entity in Y, and each entity in Y is
associated with at most one entity in X. eg dept-headdept
 One-to-many: X-Y is 1:M when each entity in X can be
associated with many entities in Y, but each entity in Y is
associated with at most one entity in X. eg deptemployee
 Many-to-many: X:Y is M:M if each entity in X can be
associated with many entities in Y, and each entity in Y is
associated with many entities in X ("many" =>one or more
and sometimes zero)
BY: MA
Cont…

 Existence
– denotes whether the existence of an entity instance is
dependent upon the existence of another, related, entity
instance
 Mandatory: every instance of one entity must participate in a
relationship with another entity.
 Optional: any instance of one entity might participate in a
BY: MA relationship with another entity, but this is not compulsory.
… Relationship Sets

– Cardinality

21
BY: MA
E/R Diagram
 Rectangles - for the Entity sets,
– Double border Rectangles - for the weak entity sets.
 Ellipses - for the Attributes,
– Double border Ellipses - for the multi-valued attributes.
– Dashed border Ellipses - for the derived attributes.
– Composite attributes are represented by linked ellipses.
 Diamonds - for the Relationships, and
 Lines - for the links between the attributes and the entity sets
and between the entity sets and the relationships.
– Arrow Head Line - for the link between an entity set with many-to-
one relationship.
 The arrow is headed to the one side entity set.
22
BY: MA
BY: MA
Example on Requirement Analysis
 The problem is to design a database system for “X
Household and Office Furniture P.L.C” based on the
following information.
– The information are kept on daily basis about what the
employees do, what resource they use, which furniture are
made out of the resource, and all the sale and order records.
– Furniture is produced by an employee from resource (s).
– Every furniture is described by the furniture Id, catalog no,
model type, color, production start date, production complete
date and price; and every resource is described by stock no,
type, current cost, and avail quantity.
– A sale of furniture is made with a receipt for both regular
24 customers and buyers.
BY: MA
… Example on Requirement
Analysis
 Regular customers are described by customer Id, name,
address and contact person; where as, no detail record is
established for buyers.
 Orders for furniture are allowed only for regular customers and
in ordering a furniture, the customer may pay part of the total
price and left in debt, then pay the debt in some other time.
 For the payment transactions three types of receipt are used;
one for sale, one for order and one for due payment (debt).
 A single receipt of each type is prepared only for one buyer or
customer but a number of furniture can be sold or ordered by
one receipt.
25  Every receipt is prepared by Sales and it has receipt number,
BY: MA prepared date, total price, and tax.
 Draw ER diagram for the previous requirement
analysis?
1. Identify the entities
2. Obtain the attributes of the entity
3. Identify the relation ship between the entities
• Entity : • Relationship • Attributes
• Furniture • Order • Furniture :fid,---
• Resources • Produced • employees :eid--
• employees • sold • Sales :id
• Sales
• customers
• customers
• receipt • receipt
BY: MA
… Example

BY: MA
Exercise1

 Requirements of the university (oversimplified for


illustrative purposes)
– In a University database we might have entities for
Students, Modules and Lecturers.
– Students might have attributes such as their ID, Name, and
Course whereas Lecturers might have attributes such as
LID, Name, Rank and Modules might have attributes such
as ModuleNumber, ModuleName, CrHr and could have
relationships (studies) with Student and Modules and
(tutor) with Lecturers and Modules.
 Identify entity, Attributes and relationship?
BY: MA  Draw the ER Diagram from the above requirement analysis?
Exercsise2: Country Bus Company

 A Country bus Company owns a number of buses. Each bus is


allocated to a particular route, although some routes may have
several buses. Each route passes through a number of towns. One
or more drivers are allocated to each stage of a route, which
corresponds to a journey through some or all of the towns on a route.
Some of the towns have a garage where buses are kept and each of
the buses are identified by the registration number and can carry
different numbers of passengers, since the vehicles vary in size and
can be single or double-decked. Each route is identified by a route
number and information is available on the average number of
passengers carried per day for each route. Drivers have an
employee number, name, address, and sometimes a telephone
number.
Further on E/R Diagram
 Relationship Attributes
– Attribute (s) may be used in some relationships to describe the
relationship further
 Multi-way Relationship
– multi-way relationship can be reduced to a binary relationship with
the use of
 an entity set in place of the relationship, and
 having new relationships for the links in between the participating
entity sets and the relationship.
 Cardinality Limits of a Relationship:
– 0..* or 0..∞
– 1..* or 1..∞
30 – 0..1
BY: MA
. . . Further on E/R Diagram

 Entity Set Roles in a Relationship


– Label on the link line identifies the role
– Example:
 If only two customers are allowed to make an order jointly as
Primary and Secondary
 Participation in a Relationship
– Total
 every element of the entity set is at least related to one element
in the other entity set
– Example:
 The Furniture entity set in the Produced relationship.

– Partial

31  There at least one element that is not related to any element in


BY: MA the other set
Example:

BY: MA
Design Issues

 Faithfulness
– classes or entity sets and their attributes should reflect reality

 Avoiding Redundancy
– be careful to say everything only once

 Simplicity
– avoid introducing more elements into your design than are absolutely
necessary

 Picking the Right kind of Element


– Entity Set versus Attributes
– Entity versus Relationship Sets
33 – Binary versus n-ary Relationship Sets
BY: MA
Remarks on Designing

 Choose meaningful naming for the entities,


attributes and relationships.
 Use short links.
 Cluster diagram if it has too many entities and
relationships.

34
BY: MA
Keys
 Keys are attributes or set of attributes that can be used to
uniquely identify an entity within the entity set
 Super Key also known as Super Set is then a set of one or more
attributes that can identify an entity uniquely from the entity set.
– If K is a super set (super key) then a set consisting of K is
also a super set.
 Candidate Key is the minimal super set. a Group of columns,
that uniquely identifies a row in a table.
– If the Candidate Key is selected as a key for an entity set then it said to
Primary Key.
– A candidate key has the properties of Uniqueness or Irreducibility

35
BY: MA
Relational Constraints/Integrity Rules
and keys:

 Each row of a table is uniquely identified by a PRIMARY KEY


 A primary key in E/R model is represented by underlining the attribute or
set of attributes.
 A column or combination of columns that matches the primary key of
another table is called a FOREIGN KEY which is used to cross-reference
tables.
 ENTITY INTEGRITY RULE of the model states that no component of the
primary key may contain a NULL value.
 REFERENTIAL INTEGRITY RULE : for every foreign key value in a
table there must be a corresponding primary key value in another table in
the database.
 Domain constraints/ INTEGRITY
– are requirements on an attribute value to be in a specified range of values.
BY: MA
Enhanced E/R Modeling

 Week Entity Set


 Specialization and Generalization
 Aggregation

37
BY: MA
Week Entity Set

 weak entity is uniquely identified with the help of


other entity
 The strong entity which contributes its primary key is
called the identifying or owner/dominant entity set.
 Criteria for weak entity set
– A one-to-many relationship set that relates the weak entity
set with owner entity set known as identifying relationship
or supporting relationship must exist.
– Total participation in the identifying relationship is required.
38
BY: MA
… Week Entity Set

 An attribute or set attributes with in the weak


entity set referred to as discriminator is used
to distinguish weak entities.
 Key of a weak entity set:
– Zero or more of its own attribute;
discriminator
– Key attributes of the owner (identifying)
entity set.
39
BY: MA
… Week Entity Set

 Notations
– Weak Entity sets are represented by
 Double boarder Rectangles.
– The identifying many-to-one relationship is
represented by
 Double border Diamonds.
– If the entity set has a discriminator then it is
represented by
 Underlining the attribute(s)

40
BY: MA
… Example (Weak entity sets)

– Each employee may have a number of Dependents.


Name Descr
Eid Name
Descr

Employee Depenedent on DEPENDANT

 For each dependent, we keep track of their name, sex, birth


date, and relationship to the employee.

41
BY: MA
Specialization and Generalization

 Specialization: Specialization is the process of defining a set of


subclasses of an entity type; this entity type is called the superclass of
the specialization. The set of subclasses that forms a specialization is
defined on the basis of some distinguishing characteristic of the entities
in the superclass.
– top-down process in grouping of entities that are similar in some way and distinct in
some other ways in which distinctions are made explicitly
– For example, the set of subclasses {SECRETARY,ENGINEER, TECHNICIAN} is a
specialization of the superclass EMPLOYEE that distinguishes among employee
entities based on the job type of each employee entity.
– The specialization of the EMPLOYEE entity type may yield the set of
subclasses {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}; this
specialization distinguishes among employees based on the method of pay
– Attributes that apply only to entities of a particular subclass—such as
42 TypingSpeed of SECRETARY—eng-type of engineers. These are called
BY: MA
 Generalization: The reverse of the specialization process.
– Several classes with common features are generalized into a superclass; original
classes become its subclasses
– the generalization process can be viewed as being functionally the inverse of the
specialization process.
– bottom-up approach in which multiple entity sets are synthesized into
a higher level entity set based on their common features.
– Example: CAR, TRUCK generalized into VEHICLE Because they have
several common attributes, they can be generalized into the entity
type VEHICLE, ; both CAR, TRUCK become subclasses of the superclass
VEHICLE. We can view {CAR, TRUCK} as a specialization of VEHICLE
– Alternatively, we can view VEHICLE as a generalization of CAR and
TRUCK
– EMPLOYEE as a generalization of SECRETARY, TECHNICIAN, and
… Example (Specialization & Generalization)

EMPLOYEES

ISA

ULL-TIME PART-TIME
EMPLOYEE EMPLOYEE
S S

44
BY: MA
Constraints on Specialization and Generalization

 Condition-defined vs. User-defined Lower-level Entity Sets


– Condition defined: In some specializations we can determine exactly the
entities that will become members of each subclass by placing a
condition on the value of some attribute of the superclass. For example,
if the EMPLOYEE entity type has an attribute Job_type, as shown in
Figure 8.4, we can specify the condition of membership in the
SECRETARY subclass by the condition (Job_type = ‘Secretary’)
 satisfying an explicit condition or predicate
– User-defined: the Membership in such a subclass is determined by the
database user when they apply the operation to add an entity to the
subclass.
 determined upon the entry of the entities

45
BY: MA
 Disjoint vs. Overlapping Specialization
– Disjoint: 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)
– Eg an EMPLOYEE can be HOURLY_EMPLOYEE or a
ALARIED_EMPLOYEE. Specified by ‘d’ in EER diagram
– Overlapping: If not disjointed, overlap; that is the same entity may
be a member of more than one subclass of the specialization
 allows for a higher-level entity to belong to more than one
entity
 Eg: employee can be manager also employee
 Specified by ‘O’ in EER diagram
Constraints on Specialization and
Generalization

 Total vs. Partial Specialization or Generalization:


– The second constraint on specialization is called the completeness (or
totalness) constraint, which may be total or partial.
– A total specialization constraint specifies that every entity in the
superclass must be a member of at least one subclass in the
specialization. Higher level entity must belong to one of the lower-level
entity, For example, if every EMPLOYEE must be either an
HOURLY_EMPLOYEE or a SALARIED_EMPLOYEE,
– a partial specialization, which allows an entity not to belong to any of
the subclasses. For example, if some
EMPLOYEE entities do not belong to any of the subclasses
{SECRETARY, ENGINEER, TECHNICIAN}
47  Generalization usually is total because the superclass is derived from
BY: MA
Aggregation

 E/R modeling allows relationships only between


entity sets.
 It achieve the relationship between a
relationship and an entity set or a collection of
entity sets.
– Aggregation is an abstraction through which
collection of related entity sets and relationships are
treated as high-level entities.
– It allows indicating for a relationship set (identified
through a box) to participate in another relationship
48 set.
BY: MA
… Example (Aggregation)

FURNITURE Production RESOURCE

Manages

EMPLOYEES

49
BY: MA
ER model to relational model Mapping

 ER model to relational Mapping Algorithm


7-Step Process:
1. Map Regular/strong Entity Types
2. Map Weak Entity Types
3. Map Binary 1:1 Relation Types
4. Map Binary 1:N Relationship Types.
5. Map Binary M:N Relationship Types.
6. Map Multivalued attributes.
7. Map N-ary Relationship Types.
BY: MA
ER Model

BY: MA
1. Map Regular/strong Entity Types

 For each regular (strong) entity type E in the ER schema,


create a relation R that includes all the simple attributes of E.
 Choose one of the key attributes of E as the primary key for R.
 If the chosen key of E is composite, the set of simple attributes
that form it will together form the primary key of R.

BY: MA
2. Map Weak Entity Types

 For each weak entity type W in the ER schema with owner


entity type E, create a relation R & include all simple
attributes (or simple components of composite attributes) of
W as attributes of R.
 Also, include as foreign key attributes of R the primary key
attribute(s) of the relation(s) that correspond to the owner
entity type(s).
 The primary key of R is the combination of the primary
key(s) of the owner(s) and the partial key of the weak entity
type W, if any.

BY: MA
Cont…

BY: MA
3. Map Binary 1:1 Relation Types

 For each binary 1:1 relationship type R in the ER schema,


identify the relations S and T that correspond to the entity
types participating in R.
 Choose one of the relations-say S-and include a foreign key
in S the primary key of T. It is better to choose an entity type
with total participation in R in the role of S.

BY: MA
Cont…

BY: MA
4. Map Binary 1:N Relationship Types.

 For each regular binary 1:N relationship type R, identify


the relation S that represent the participating entity type at
the N-side of the relationship type.
 Include as foreign key in S the primary key of the relation
T that represents the other entity type participating in R.
 Include any simple attributes of the 1:N relation type as
attributes of S.

BY: MA
Cont…

BY: MA
5. Map Binary M:N Relationship Types.

 For each regular binary M:N relationship type R, create a


new relation S to represent R.
 Include as foreign key attributes in S the primary keys of
the relations that represent the participating entity types;
their combination will form the primary key of S.
 Also include any simple attributes of the M:N relationship
type (or simple components of composite attributes) as
attributes of S.

BY: MA
Cont…

BY: MA
6. Map Multivalued attributes.

 For each multivalued attribute A, create a new relation R.


 This relation R will include an attribute corresponding to A,
plus the primary key attribute K-as a foreign key in R-of
the relation that represents the entity type of relationship
type that has A as an attribute.
 The primary key of R is the combination of A and K. If the
multivalued attribute is composite, we include its simple
components.

BY: MA
Cont..

BY: MA
 For each n-ary relationship type R, where n>2, create a
new relationship S to represent R.
 Include as foreign key attributes in S the primary keys of
the relations that represent the participating entity types.
 Also include any simple attributes of the n-ary
relationship type (or simple components of composite
attributes) as attributes of S.

BY: MA
BY: MA
 Reference: Database Management Systems
3rdEdition Ramakrishnan - Gehrke

BY: MA
 Thank you

You might also like