Chapter 3-Data Modelling Using Entity Relationship Model
Chapter 3-Data Modelling Using Entity Relationship Model
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
BY: MA
Data Model Basic Building Blocks
BY: MA
Cont…
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
BY: MA
Entity – Relationship (E/R) Data Model
BY: MA
Cont…
BY: MA
Cont…
BY: MA
Attributes
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
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-headdept
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 deptemployee
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
– Partial
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
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:
37
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)
41
BY: MA
Specialization and Generalization
EMPLOYEES
ISA
ULL-TIME PART-TIME
EMPLOYEE EMPLOYEE
S S
44
BY: MA
Constraints on Specialization and Generalization
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
Manages
EMPLOYEES
49
BY: MA
ER model to relational model Mapping
BY: MA
1. Map Regular/strong Entity Types
BY: MA
2. Map Weak Entity Types
BY: MA
Cont…
BY: MA
3. Map Binary 1:1 Relation Types
BY: MA
Cont…
BY: MA
4. Map Binary 1:N Relationship Types.
BY: MA
Cont…
BY: MA
5. Map Binary M:N Relationship Types.
BY: MA
Cont…
BY: MA
6. Map Multivalued attributes.
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