3 Entity-Relationship Model
3 Entity-Relationship Model
2.1
Entity Relationship Model (ER)
2.2
What is an entity ?
An entity is a “thing” in the real world with
an independent existence.
2.3
Entity and Entity Set
Two types of entities:
Strong entity: can exist independently (or can
uniquely identify itself)
Weak entity: existence depends on the
existence of other (strong) entity or entities
Examples:
An employee is a strong entity but the
dependents of the employee could be weak
entities
An account in a bank is a strong entity but a
transaction could be a week entity
2.4
Entity and Entity Set
An entity type defines a set of entities that have
the same attributes.
STUDENT is an entity type ( Schema)
2.5
Attributes
An entity has a set of attributes that describes it.
Person(SSN, Name, Address, Job-description,
Salary).
An entity will have a value for each of its attributes
(999-010-201, John Smith, ‘20 Alebany Rd,
Cardiff, UK’, ‘Manager’, 2500)
Definition: The properties of an entity set are called
attributes of the entity set.
Students: SSN, Name, Address, GPA, Status, ...
Books: Title, ISBN, Authors, Publisher, Year, ...
For a given application, only a limited number of
attributes of an entity set are of interest
2.6
Types of Attributes
Simple (or atomic) attribute is a one which
cannot be divided into smaller parts.
Examples: SSN, GPA, Salary.
Composite attribute is an attribute which can
be divided into smaller subparts, these
subparts represent more basic attributes with
independent meanings of their own.
Examples: Name: First_Name,
Middle_Name, Last_Name
Address: Street_Address, City, State, Zip
code
2.7
An Example of a composite attribute
Address
2.8
Types of Attributes
A single-valued attribute is a one which has
one (single) value for a particular entity.
Example: Age, BirthDate
A multi-valued attribute is a one which may
have one or more values for the same entity.
Multi-valued attributes may have lower and
upper bounds on the number of values for an
individual entity.
College Degrees for Person: 0, 1, 2, 3, …
Color for a Car: 1, 2, …..
Authors of Books
Phone Number
2.9
Types of Attributes
A stored attribute is a one whose value is
explicitly stored in the database.
e.g. name, birth-date.
Derived-attributes: whose values are computed
from other attributes.
Examples: Age from Birthdate
Annual Salary from Monthly Salary
NoOfEmployees ==> Count number of
employees in the Employee table.
2.10
Null Values
An attribute may have null as its value.
Null may mean
not applicable (college degree)
Unknown
2.11
Keys
Key attribute is an attribute whose values are
distinct (unique) for a given entity type.
Keys may be
simple: one attribute (SSN), or
composite: a set of attributes whose values
together uniquely identify an entity type
Name(first name, father name, grandfather
name, family name)
2.12
Value Sets or Domains
A value set V or domain for a simple attribute A
specifies the set of values that may be assigned to
that attribute for each individual entity.
e.g. Employee.Age Age >=16 and Age <=60
2.13
Complex Attribute
{AddressPhone({Phone(AreaCode, Phone#)},
Address(StreetAddress(No, Name, AptNo), City,
State))}
The above example states that a person may have
several residences and each residence may have
several phones. Phone numbers consist of area
code and phone number. Address, by contrast,
consists of street, city and state. Street address is a
composite attribute which consists of street
number, name and apartment number.
( ) : indicates a composite attribute
{ }: indicates a multi-valued attribute.
2.14
Relationship Types
Each entity type E1, E2, …, En is said to participate
in the relationship type R.
A relationship type is represented as diamond-
shaped box which is connected by straight lines.
2.15
Relationship Degree
Binary Relationships
2.16
Ternary Relationships
PART
2.17
Ternary Relationships
COUNTRY
2.18
Recursive Relationships
EMPLOYEE Supervises
PERSON Marry
2.19
Relationships
The role name signifies the role that a
participating entity from the entity type plays in
each relationship instance. Going back to the
previous example, the entity e1 plays the role of
a supervisor, while entity e2 plays the role of a
supervisee.
2.20
Cardinality Ratio
Specifies the number of relationship instances that an
entity can participate in. Common cardinality ratios
for binary relationship types are 1:1,1:N, and M:N.
2.21
N 1 COMPANY
EMPLOYEE WORKS-FOR
2.22
1 1 MANAGER
DEPARTMENT HAS
2.23
M N PROJECT
EMPLOYEE WORKS-ON
2.24
Participation Constraints
Specifies whether the existence of an entity
depends on its being related to another entity
via the relationship type. There is total and
partial participation.
2.25
Total participation
N 1
EMPLOYEE WORKS-FOR DEPARTMENT
Total
participation.
2.26
Partial participation
1 N
PERSON Buys CAR
2.27
Total & Partial participation
1 N
PROFESSOR Manages DEPARTMENT
N 1
EMPLOYEE Works-for DEPARTMENT
Start-Date
2.29
A weak entity type is an entity which does not have
any key attributes
1
identifying relationship
Dependents
Fname
N Sex
Dependent
Birthdate
Relationship
2.30
Weak Entity Types
2.31
ER Notations
<Name> Attribute
Multi-valued
<Name>
attribute
2.32
ER Diagram Notations
2.33
ER Notations
<Name> <Name>
2.34
Entity Types: singular name, capital letters
Relationship Types: usually singular verbs,
capital letters.
Attribute: nouns, capitalized.
Role names: are in lowercase letters.
ER diagrams are drawn such that they are
readable from left to right and top to bottom
(Except weak entity types).
2.35
ER Notations
E1 R E2 Total participation of E2 in R
1 N
E1 R E2
2.36
Relationships
Several relationships may exist among the same
set of entity sets.
m Works_in 1
Employees Departments
1 1
Manages
2.37
Degree of a Relationship (1)
2.38
Degree of a Relationship (2)
Binary relationship (degree = 2)
Examples:
2.39
Cardinality (1)
One-to-one (1-to-1) relationship between E1 and
E2:
for each entity in E1, there is at most one
associated entity in E2, and vice versa.
Examples of 1-to-1 relationships:
Binary 1-to-1 relationship
2.40
Cardinality (2)
2.42
ER Diagram (1)
Recursive relationship
is_married_to
1 1
Person
2.43
ER Diagram (2)
binary relationship
1 m
Professor advises Student
2.44
ER Diagram (3)
ternary relationship
Engineer
Skill_used
Skill Project
2.45
Role of an Entity Set (1)
m takes n
Student Course
1 is_TA_of 1
2.46
Role of an Entity Set (2)
is_married_to supervises
1 1 1 m
2.47
Attribute of Relationship (1)
m n
Student takes Course
grade
2.48
Attribute of Relationship (2)
Another example:
Supplier
m Quantity
orders
n r
Part Project
2.49
Cardinality Constraint (1)
One in ER model means zero or one
Many in ER model means zero or more
Cardinality constraints make them more precise
2.50
Cardinality Constraint (2)
General format:
0 min_card max_card
Interpretation:
(min_card, max_card)
E R
2.51
Cardinality Constraint (3)
Definition:
If every entity in E involves at least one
relationship in R (i.e., min_card >= 1), E is said
to have total participation in R
If min_card = 0, E is said to have partial
participation in R
2.52
Cardinality Constraint (4)
(0, 1) (1,1)
Employee manages Department
2.53
Representing 1-to-1, 1-to-m, m-to-m
Relationships
(0, 1) (0, 1)
one-to-one: E R F
(0, m) (0, n)
many-to-many: E R F
(0, m) (0,1)
one-to-many: E R F
1 m
E R F
2.54
An Example Database Application
Company Database
2.55
An Example Database Application
The Company database keeps track of a company’s
Employees, Departments, Projects
The following are the requirements and
specifications
The company is organized into departments.
Each department has a:
unique name, unique number
particular employee who manages the
department
We keep track of the start date when that employee
began managing the department
A department may have several locations
2.56
An Example Database Application
A department controls a number of projects, each
of which has a
unique name, unique number, and single
location
We store each employee’s
name, social security number, address, salary,
sex, and birth date.
An employee is assigned to one department but
may work on several projects, which are not
necessarily controlled by the same department
We keep track of the number of hours per week
that an employee works on each project
We keep track of the direct supervisor of each
employee
2.57
An Example Database Application
We want to keep track of the dependents of each
employee for insurance purposes.
We keep each dependent’s first name, sex, birth
date, and relationship to the employee
2.58
ER diagram for the company database
Each department has a unique name, a unique number, particular employee
who manages the department. A department may have several locations.
DEPARTMENT NumberOfEmployee
2.59
ER diagram for the company database
A department controls a number of projects, each of which has a unique
name, unique number, and single location
PROJECT
2.60
ER diagram for the company database
We store each employee’s name, social security number, address, salary,
sex, and birth date.
Minit Lname
Fname
Sex
EMPLOYEE Salary
BDate
2.61
ER diagram for the company database
We want to keep track of the dependents of each employee for insurance
purposes. We keep each dependent’s first name, sex, birth date, and
relationship to the employee
Fname Relationship
Sex
BDate
DEPENDENT
2.62
ER diagram for the company database
Each department has a particular employee who manages the department
We keep track of the start date when that employee began managing the
department
(0,1) (1,1)
EMPLOYEE MANAGES DEPARTMENT
manager
department
managed
StartDate
2.63
ER diagram for the company database
An employee is assigned to one department.
(1,1) (1,N)
EMPLOYEE WOKES-FOR DEPARTMENT
employee department
2.64
ER diagram for the company database
A department controls a number of projects
(0,N) (1,1)
DEPARTMENT CONTROLS PROJECT
controlling controlled
department project
2.65
ER diagram for the company database
An employee is assigned to one department but may work on several
projects, which are not necessarily controlled by the same department. We
keep track of the number of hours per week that an employee works on each
project
(0,N) (1,N)
EMPLOYEE WORKS_ON PROJECT
worker project
Hours
2.66
ER diagram for the company database
We keep track of the direct supervisor of each
employee
EMPLOYEE
(0,N) (0,1)
supervisor supervisee
SUPERVISION
2.67
ER diagram for the company database
We want to keep track of the dependents of each
employee for insurance purposes.
(0,N) (1,1)
EMPLOYEE HAS DEPENDENT
employee dependent
2.68
End of Chapter 3
2.69