Entity Relationship Notes
Entity Relationship Notes
Model
Davood Rafiei
Conceptual Schema
E-R Modeling
Design
Mapping to DBMS
Relational Model Data Model
2
ER Model Overview
ER Model Basics
4
ER Model Basics
Relationship: represents the fact that certain
entities are related to each other.
• e.g. John has taken CMPUT 291.
Relationship set: set of relationships of the
same type.
Examples of relationship sets:
• students enrolled in courses
• cars registered to owners
• passengers booked on flights
Graphical representation:
enrolled registered booked
5
ER Model Basics
name dest
students cars flights
6
ER Model Basics
Examples name
sin
since
name pname Employees
sin pno budget
super- subor-
visor dinate
Employees Works_On Projects
Reports_To
8
Constraints and Complications
Key constraints
• in binary relationships:
binary relationship types
• in general relationships
Participation constraints
Set-valued attributes
Weak entities
ISA hierarchies
Constraint: none.
• Alternative representation
N N
Employees Works_On Projects
10
Binary Relationship Types: Many-to-One
11
12
Ternary Relationships
Parts
13
Participation Constraints
Does every project have a supervisor?
• If so, this is a participation constraint: the participation of Projects
in Supervises is said to be total (vs. partial).
Every pid value in Projects table must appear in a row of the
Supervises table (with a non-null sin value!)
since
name pname
sin pid budget
Works_On
since
14
Set-Valued Attributes
Each employee can have one or more hobby.
• Attribute value can be a set (in contrast to relational model)
• E.g. (111111, John, (stamps, coins))
name
hobby
sin
Employees
15
Weak Entities
name
cost dname age
sin
16
Weak Entities
Prof
Examples:
name teaches
cid sno
17
ISA Hierarchy
Consider forming a new entity set as the union
of two or more entity sets.
name
sin
Employees
hourly_wages hours_worked
ISA
contractid
Attributes and relationships
common to all lower-level Contract_Emps
Hourly_Emps
entity sets are moved to the
higher-level entity set. Contract_Emps and Hourly_Emps cover Employees.
18
ISA Hierarchy (cont.)
ISA
Undergrad_students
major
19
Properties of ISA
Inheritance
• Attributes of supertype are attributes of subtype
• Key of supertype is key of subtype
• Relationship of supertype is relationship of subtype
Transitivity - Hierarchy of IsA
• Undergard student is subtype of Student, Student is subtype of
Person, so Undergard student is also a subtype of Person
Reasons for using ISA:
• Makes ER diagram more concise and readable.
• Common attributes/relationships need not be
repeated.
20
ISA Constraints
name
Covering constraints: ssn
Hourly_Emps Contract_Emps
Contract_Emps entity?
(default:disallowed)
21
22
Entity vs. Attribute
Should address be an attribute of Employees or an
entity (connected to Employees by a relationship)?
Depends on the use we want to make of address
information and the semantics of the data:
• is it an object that we want to keep information about
(independent from employees)?
• does it participate in a relationship with an entity other than
employees?
• are there many employees with no addresses?
• can several employees share the same address?
A positive answer to one or more of those questions
implies address better be modeled as an entity.
23
• first diagram: No
• second diagram: Yes
from Duration to
time
apptnum Mgr_Appts
budget
time budget
25
Parts
27
28
Summary of ER (Contd.)
29
ER Exercise
• Professors have a SIN, a name, an age, a rank, and a research specialty.
• Projects have a project number, a sponsor name (e.g. NSERC), a starting date, an
ending date, and a budget.
• Graduate students have a SIN, a name, an age, and a degree program (e.g. MS or PhD)
• Each project is managed by one professor (principal investigator).
• Each project is worked on by one or more professors (co-investigators).
• Professors can manage and/or work on multiple projects.
• Each project is worked on by one or more graduate students (research assistants).
• When graduate students work on a project, a professor must supervise their work
on the project. Graduate students can work on multiple projects, in which case they
will have a (potentially different) supervisor for each one.
• Departments have a department number, a department name, and a main office.
• Departments have a professor (chairman) who runs the department.
• Professors work in one or more departments, and for each department that they
work in, a time percentage is associated with their job.