CS 4310: Software Engineering
Lecture 5
Entity Relationship Modelling
2
Entity-Relationship Model
Technique for carrying out the conceptual and logical design of the system
A widely accepted data modelling approach
3 basic notions:
» entities» attributes» relationships
3
What is an entity?
An entity is an object that can be identified in the users’ work environment and that users want to track.
4
• An entity is a thing or object in the real world (within the application context)
• An entity has a set of properties which uniquely identify it.
• An entity is represented as a rectangle in an ER diagram
Entities
Project
5
What is an Attribute?
An attribute describes a characteristic of an entity
For example:- An entity: Employee
- Has attributes:
» Employee_Name
» Extension
» Date_Of_Hire
6
Example: Project = (proj_name, location, budget,
start_date, end_date)
Represented as ellipses in an ER diagram
Projectproj_name
locationbudget
start_date
end_date
Attributes
7
What are Relationships?
Relationships are associations between entities which express some real world relationship
Project EmployeeEmploys
• Project and Employee participate in the employs relationship
• The function that an entity plays in a relationship is called that entity’s role
8
Road Town
ends at
starts at• There can be more than
one relationship between entities.
• There can be recursive relationships that can indicate roles for clarity.
• A relationship can also have descriptive attributes.
Employee works for
Client Bookorders
date
manager
worker
Relationship Sets
9
Degree of Relationships
Refers to the number of entities participating in a relationship
Most relationships are binary (degree 2), but can also have ternary (degree 3) relationships.
Project ContractorHires
Contract
number
value
start_date
end_date
Name
Address
proj_name
location
budget
start_dateend_date
10
Express the number of entities to which another entity can be associated via a relationship
For a binary relationship, the mapping cardinality can be one of the following:
• one to one
• one to many
• many to one
• many to many
Mapping Cardinalities
11
Cardinality Examples
A person has only one ID book and an ID book belongs to only 1 person
A person can own many cars (possibly 0), but a car only has 1 owner
A person can own many houses and a house can have multiple owners
Person ID Bookowns
Person Carowns
Person Houseowns
12
Design Issues
Entity or Attribute?
• Example: should location be an entity or an attribute?
• can a project be in more than 1 location?
Entity or Relationship?
• generally: relationships for actions between entities
• whatever “makes sense” in application context
13
ER Diagram Symbols
Entity Set
Attribute
Relationship
One-to-one link
Many-to-one link
Many-to-many link
14
Example ERD
Project Employeeemploys
Alienspecies
area
start_date
first_name
position
proj_name
location
budgetstart_date
end_dateID surname
year_joined
year_leftend_date
eliminates
15
ER Design: Where to Start
• Identify entity sets
• Describe the entity sets with attributes
• Specify relationships and cardinalities
16
• Every department within the company is in only one division.
• Each division has more than one department in it.
• There is no upper limit on the number of departments that a division can have.
Simple Modelling Example
17
Division
Department
Employee
1. Define Entities
18
2. Define Relationships
Division
Department
Employee
contains
manages
19
Division
Department
Employee
contains
manages
3. Define Cardinality
20
Standard Notation
INVOICE
is sent by
A B
A B
A plain rectangle is used to represent the entity type.
A labeled line to represent the relationship.
1 : 1
1 : N
21
Diagram with Standard Notation
Division
Department
Employee
contains
manages
22
COURSE STUDENThas enrolled
LOAN BOOKrefers to
ONE loan refers to ONE book.ONE book is referred to ONE loan.
ONE course has enrolled ONE or MORE students.ONE student is enrolled on ONE course.
Notation Examples
23
• Any one supplier might supply more than one kind of part.
• Any one kind of part might be bought from a number of different suppliers.
SUPPLIER PARTsupplies
Many-to-Many Relationship Example
24
More Examples
Customer Order
Customer Property
Teachers Studentsteach
can place
is associated
25
WARD
NURSE PATIENT
DOCTOR
treatsaccommodateshas
assigned
AILMENTsuffersfrom
caresfor
Example - Simple Hospital System
26
DEPARTMENT
LECTURER
STUDENT
COURSE
is_in
enrols
teaches
offers
College System
27
Your Project Work
• Develop Requirements Document.
• Think about your system’s entities and relationships