Data Modelling Using Entity-Relationship Model
THE PROCESS OF DATABASE DESIGNENTITY-RELATIONSHIP (ER) MODEL
ENHANCED ENTITY-RELATIONSHIP (EER) MODEL
D. Christozov / G.Tuparov INF 280 Database Systems: ER/EER Model 1
The Process of DB Design (1)
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 2
The Process of DB Design (2)
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 3
Simplified diagram of the process
Mini-world
Conceptual Data ModelER/EER Diagram
modellingdesign
refinement
Collection of requirements:Analysis&Specification
Data and Functional Requirements
research
Logical design
Physical DesignDBMSdependent
DBMS independent
The Process of DB Design (3)Requirements Collection and Analysis• Goal: to understand and document the data
entities, their attributes, relationships between them, and how they are used.
• Techniques:– Interviews with end-users;– Analysis of content of existing documents;– Analysis of procedures for documents’ circulation;– Writing scenarios of document processing;– Etc.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 4
The Process of DB Design (4)The success of a database development project depends on how well the designers understand the “mini-world” and how adequate is the model built to the purpose of the project.Design principles:– Faithfulness: all assertions, assumptions, etc. should make
sense in the scope of the mini-world;– Avoiding redundancy;– Simplicity;– Be careful in deciding whether a data element is an entity
or represents a relationship between entities;– Choose the right relationship between entities.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 5
ER and EER modelsNeed of conceptual languages:
To enhance understanding between users and designers
Users know what they need – “mini-world” jargon.Designers know how to develop databases – DB jargon.
ER and EER are graphical languages to simplify communication between parties!
Descriptions of data requirements are diagrams!
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 6
ER/EER models - Entities and Attributes• The basic object that the ER model represents is an
entity, which is a thing in the real world with an independent existence.
• An entity may be an object with a physical existence (for example, a particular person, car, house, or employee) or it may be an object with a conceptual existence (for instance, a company, a job, or a university course).
• Each entity has attributes - the particular properties that describe it.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 7
ER/EER models – Entity Types and Entity Sets
• A database usually contains groups of entities that are similar. An entity type defines a collection (or set) of entities that have the same attributes.
• Each entity type in the database is described by its name and attributes.
• The collection of all entities of a particular entity type in the database at any point in time is called an entity set; the entity set is usually referred to using the same name as the entity type.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 8
ER Model: basic elements• Entity-relationship model is graphical in nature. • Basic elements are:– Entity set is representing with rectangular
– Attribute is representing with ellipses
– Relationship is representing with diamond
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 9
EntityName
AttributeName
RelationshipName
ER Model: diagram• Edges connect entity-sets to attributes and connect
relationships to entity sets.• Example: Movies and stars
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 10
Play_inMovies
typelength
yearTitle
Stars
Address
Name
role
ER Model: Entity (1) Entities are objects with physical or conceptual existence• Entity Types: description of group (class) of entities• Entity Sets: the set of instances of an Entity Type• Attributes: properties describing an entity –
domain (value set)– Atomic vs. Composite (Street Number vs. Address)– Single-Valued vs. Multivalued (Car model vs. Car colors)– Stored vs. Derived (Birt_Date vs. Age)– Null vs. Not Null (Not applicable, missing/not known)– Nested (Attributes can be nested arbitrarily)
• Keys: attribute(s) identifying uniquely any instance
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 11
ER Model: Entity (2) Examples• Entity-set “Movies stars”:
Name AddressSharon Stone CaliforniaArnold Schwarzenegger California
• Entity-set “Movies”:Title Year Length TypeBasic Instinct 1998 2h 15’ dramaTotal recall 1998 1h 55’ action
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 12
E/R Model: Relationship (1)• Type: define the associations among
entities in related entity-types;• Set: the set of associations among individual
entities in the related entity-sets;• Instance: association between instances of related
entity-sets, participated in the relation;• Structural Constraints:– cardinality ratio: specifies the number of relationship
instances that an entity may participate in;– participation: specifies whether the existence of an entity
depends on its being related to another entity via the relationship.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 13
E/R Model: Relationship (2)Cardinality Ratio: Graphical notations1:1 One entity of E1 is related at most with one entity from E2.
1:N One entity of E1 may relate to many entities from E2, and one entity of E2 relate to at most one entity from E1.
M:N One entity of E1 may relate to many entities from E2, and one entity of E2 may relate to many entities from E1.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 14
E1 E2R1 1
E1 E2R1 N
E1 E2RNM
E/R Model: Relationship (3)Participation: Graphical notations
E1 participates totally, and E2 participates partially: if any entity of E1 participates in R, but not any entity of E2 participates in R.
Both E1 and E2 participate totally.
Both E1 and E2 participate partially.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 15
E1 E2R
E1 E2R
E1 E2R
E/R Model: Weak Entity TypeEntity type, which entities exist and are identified only through their participation in a relationship is called weak entity type. Graphical notation:
E1 – identifying or owner entity type (strong)R – identifying relationshipE2 – identified or weak entity type
Notes:1. E2 participates totally in R2. Identification (key) of an E2 entity is composed by the key of E1 and
the own partial key (which identify the entity among the group identified by the same instance of E1).
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 16
E1 E2R
E/R Model: Case “Company’s Personnel”
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 17
“We need something small, just to keep track to employees record: Name, SSN, Address, Birth date, Sex, and Salary; to which
department s/he works for.” Let us sign the contract!
“Of course, we have to know who manages departments, and departments’ name and number, and location. Some departments are located in more than
one room.”
“Salaries are divided according the personal contribution, measured in hours, to projects’ account. Every project is controlled by one department and is described by name,
number, and location. Every project may be developed by several employees, and one employee may work for several projects.”
“I have forgotten, but we need to know who are dependents of our employees. Because they are beneficiaries of insurances we pay. We want to know their name, sex, birthday, type of relationship,
and also who of the employees supports them.”
“O, yes, we have a system that employees are assigned a supervisor – another employee…”
E/R Model: Case “Company’s Personnel”• COMPANY– Employees, departments, and projects– Company is organized into departments– Department controls a number of projects– Employee: store each employee’s name, Social
Security number, address, salary, sex (gender), and birth date
– Keep track of the dependents of each employee
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 18
E/R Diagram: Case “Company’s Personnel”
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model19
Sal
Fn
Nam
Min Ln
AddrSex
BD
SSN EMPLOYEE Works_forN
1
Manage
11
supervision
1
N
Name
Location
Number
PROJECT
Name Sex BDate Relationship
DEPENDENT
Controls
1
N
Depend_of
N
1
Works_on
N
M
hours
Number
LocationName
DEPARTMENT
NumEmp
E/R Model: RefinementE/R Model refinement is a process which may:1. Increase complexity of particular part of the model
by adding more details: – Instead of using attribute department to employee entity,
we add a new entity department with two relationships with employee;
– If we know more precisely some constraints, instead of very general total/partial participation we can use (min/max); etc.
2. Decrease complexity by removing some unneeded details. – E.g. details about project has nothing in common with
personal records.D. Christozov / G.Tuparov
INF 280 Database Systems: ER/EER Model 20
Enhanced Entity-Relationship and Object Modelling
• Object-Oriented programming:– Abstraction– Encapsulation– Hierarchy
• Unified Modelling Language (UML) is the tool for conceptual design of OO application
• EER is an OO extension of ER. It introduces the concepts: – Subclasses– Super-classes – Inheritance
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 21
EER: specialization generalization (1)• Specialization is a 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 characteristics of the entity in the superclass.
• Generalization is the process of abstraction in which we suppress the differences among several entity types, identify their common features, and generalize them into a single superclass of which the original entity types are special subclasses.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 22
EER: specialization generalization (2)
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 23
BD
Fn
Nam
Min Ln
AddrSSN
EMPLOYEE
MANAGERU
U U
MONTHLY_PAID HOURLY_PAID
SECRETARY TECHNICIAN ENGINEER
U
U UU
E_type
T_Grade
T_Speed
d
manages
PROJECT
BelongsTRADE_UNION
d
Ì - subset symbold - disjoin
EER: specialization generalization (3)• Constraints and Characteristics– predicate-defined vs. user-defined
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 24
BD
Fn
Nam
Min Ln
AddrSSN
EMPLOYEE
Job_Type
Defining attribute
Value-set of defining attribute
MANAGER
No automatic
SECRETARY TECHNICIAN ENGINEER
U
U UU
E_type
T_Grade
T_Speed
Job_type
secretary
technician
engineer
d
U
EER: specialization generalization (4)• Constraints and Characteristics– disjoined vs. overlapped
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 25
BD
Fn
Nam
Min Ln
AddrSSN
EMPLOYEE
U U
MONTHLY_PAID HOURLY_PAID
d
ENGINEER MANAGER
o
EER: specialization generalization (5)• Constraints and Characteristics:– total vs. partial specialization– insert/delete/modify in specialization– hierarchies and lattices: • shared sub-class multiple inheritance
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 26
EER: specialization generalization (6)• Multiple super-classes– UNION vs. INTERSECTION
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 27
bank company person
u
owner
salary_paidengineer
manager
Relationship Types of Degree higher than two (1)
1. Transform ternary ER model into binary
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 28
Relationship Types of Degree higher than two (2)
1. Transform ternary ER model into binary (cont.)
2. Use ternary (or higher) as it is:– Cardinality (1 or N) is specified for every entity
(We cannot speak for cardinality ratio!)– Participation is defined as usual: total and partial.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 29
Q & A
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 30
Examples: Fancy FruitsDraw the ER diagram for the following “mini-world”:Fancy FruitsFancy Fruits is a specialty grocery store supplying a variety of boxed fruits to its customers. The entities are customers, orders, stock, and vendors. The stock keeps track to current inventory (quantities on-hand of the items and current price). The vendors lists the wholesalers who supply Fancy Fruits with items, it includes the cost of item for Fancy Fruit and geographical region, where the wholesaler is located (Hint: Consider that one vendor could supply a number of items and one item could be supplied by a number of vendors - different regions and costs). The customer also store information about the region of the customer as well as customer_name and phone. Orders defined the quantities of given item ordered by a customer.D. Christozov / G.Tuparov
INF 280 Database Systems: ER/EER Model 31
Examples: Quack ConsultingDraw the ER diagram for the following “mini-world”:Quack ConsultingQuack Consulting is a computer consulting firm. It keeps the list of its clients (id, name, phone). Each of them may have many different projects (id, description, start_date, due_to, team_leader). A project may consists of several tasks (project_id, task_id, consultant, description, start, due_to). Only one consultant is ever assigned to a given task. The time a consultant works for a project is recorded in time table. In order to choose the appropriate consultant for a client information about consultants and his/her specialty (including the billing_rate) is maintain as well as some comments about his/her qualities important for Quack Consulting.
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 32
Examples: Chains’ SupplierWhat “mini-world” the following ER diagram represents:
D. Christozov / G.TuparovINF 280 Database Systems:
ER/EER Model 33
Retailers
M
Id
Name
Price
On_hand
Products
Codes
D_codeD_Price
PurchaseDate
Quantity
C_Id
Name
address Customers Dealersd
N
C_ID
Quantity
D_code
Orders
Date
N
M
N
M