ER Model
ER Model
2
Overview of Database Design Process
• Database application
– refer to a particular database, e.g. a BANK database
• Methodology:
– Use E-R model to get a high-level graphical view of essential
components of enterprise and how they are related
– E-R diagram
– Convert E-R diagram to DDL
• Entity type/set:
– Collection of entities of the same type that share the
same properties
• Set of all employees, companies, trees, holidays
7
Entity-Relationship Model
• Attribute:
– Properties used to describe an entity
• EMPLOYEE entity attributes: Name, SSN, Address, Gender,
BirthDate
• amendment_5 = (number, definition)
– A specific entity have a value for each of its attributes
• A specific employee entity may have Name = ‘Neena’, SSN =
‘1234’, Address = ‘731, Daya Vihar, Delhi’, Gender =‘F’,
BirthDate = ‘09-01-85’
– Each attribute has a value set (Domain or data type)
associated with it
8
Entity-Relationship Model
• Relationship:
– Association among two or more entity sets
• Relationship type/set:
– Collection of similar relationships
• Examples:
– Employee and Department
– Employee and Project
9
A Simple Example - “Movie Database”
• Entity:
– Movie, Star
• Attributes:
– Name: “********” (simple, single-valued / multivalued)
– Address: “123, Malabar Hill, Mumbai” (complex)
– Birthdate: “1-1-80” (simple)
– Age: 34 (could be derived from Birthdate and current date)
• Entity Types:
– Stars (Name, Address, Birthdate, Age)
– Movies (Title, Year, Length, FilmType)
• Relationship Type:
– Works_in (Name, Title, Year)
10
Types of Attributes (1/5)
• Null
11
Types of Attributes (2/5)
• Simple versus Composite
– Simple (or atomic): Each entity has a single atomic value for the
attribute; e.g., SSN or Gender
– Composite: Composition may form a hierarchy where some
components are themselves composite
• e.g., Address(StreetAddress, City, State, Zip)
12
Types of Attributes (3/5)
• Single-valued versus Multivalued
– Single-valued: a single value for a particular entity; e.g., Age
– Multivalued: An entity may have multiple values for that attribute
• e.g., PreviousDegrees attribute for a person
• Denoted as {PreviousDegrees}
13
Types of Attributes (4/5)
• Stored versus Derived
– The Age and BirthDate attributes of a person
– Age: a derived attribute; BirthDate: a stored attribute
• Complex attributes:
– e.g., if a person can have more than one residence and each
residence can have multiple phones
14
Types of Attributes (5/5)
15
Entity Type and Keys
• Key attribute: An attribute of an entity type for which each
entity must have a unique value is called a key attribute of
the entity type
– Example: SSN of EMPLOYEE, Roll No. of a student
19
Database Application Ex: Company DB
• Keeps track of a company’s employees, departments, and projects
– The company is organized into DEPARTMENTs.
• Each department has a unique name, a unique number, and a particular
employee who manages the department
• Keep track when that employee began managing the department
• A department may have several locations
• A department controls a number of PROJECTs, each of which has a unique
name, a unique number, and single location
– Store each EMPLOYEE’s name, ssn, address, salary, gender, and birth date
• Each employee works for one deptt. but may work on several projects
• Keep track of the no. of hours/week that an employee works on each project
• Keep track of the direct supervisor of each employee
• Each employee may have a number of DEPENDENTs
• Keep each dependent’s first name, gender, birth date, and relationship to the
employee 20
Initial design of Entity Types for the
COMPANY Database Schema
• Based on the
requirements, four
initial entity types are
identified in the
COMPANY database: incomplete
– DEPARTMENT design
– PROJECT
– EMPLOYEE
– DEPENDENT
• The initial attributes
are derived from the
requirements
description 21
Refinement: Introducing Relationships
• A relationship relates two or more distinct entities with a
specific meaning
– EMPLOYEE Hina works on the Container PROJECT
– EMPLOYEE Umesh Gupta manages Research DEPARTMENT
Refined
27
Recursive Relationship Type
• Same participating entity type in distinct roles
• SUPERVISION relationship: Employee participates twice in two
distinct roles
29
Weak Entity Types
31
Constraints on Relationship Types
• Two types of relationship constraints
– Cardinality Ratio (specifies maximum participation)
• One-to-one (1:1), One-to-many (1:N) or Many-to-one, and
Many-to-many (M:N)
M:N
33
Participation Constraints
• Specifies the minimum number of relationship instances that
each entity can participate in
• Total participation constraint
– The participation of an entity type in a relationship type is total if
every entity must participate in at least a relationship of this
relationship type
– Ex: Company policy - every employee must work for a deptt.
– Displayed as a double line
34
Participation Constraints
• Specifies whether the existence of an entity depends on
its being related to another entity via the relationship type
35
Attributes of Relationship Types
– Startdate of MANAGES (1:1 relationship)
36
Attributes of Relationship Types
– HoursPerWeek of WORKS_ON
• Its value for each relationship instance describes the number of
hours per week that an EMPLOYEE works on a PROJECT.
• Value depends on a particular (employee, project) combination
– Startdate of MANAGES
• Its value for each
relationship instance
describes the date on
which a manager started
managing a department
37
Final ER Design for the COMPANY
Database
The cardinality ratio
and participation
constraint of each
relationship type are
determined from the
listed requirement in
Slide no. 25
• MANAGES
–1:1 relationship type b/w EMPLOYEE and DEPARTMENT
–EMPLOYEE participation is partial
–DEPARTMENT participation is total (assume a department must have
a manager at all times)
–The attribute StartDate is assigned to this relationship type 39
Final ER Design for the COMPANY
Database
• CONTROLS
– 1:N relationship type between
DEPARTMENT & PROJECT
– The participation of PROJECT
is total
– The participation of
DEPARTMENT is partial
(user’s consultation indicates
that some deptt may control
no projects)
• WORKS_ON
– M:N relationship type with attribute Hours (since a project can
have several employees working on it)
– Both participations are total
40
Final ER Design for the COMPANY
Database
• SUPERVISION
– 1:N relationship type between
EMPLOYEE (in the supervisor
role) and EMPLOYEE (in the
supervises role)
– Both participations are partial
(since not every employee is a
supervisor and not every
employee has a supervisor)
• DEPENDENTS_OF
– 1:N relationship type between EMPLOYEE and DEPENDENT
– It is the identifying relationship for the weak entity type DEPENDENT
– The participation of EMPLOYEE is partial
– The participation of DEPENDENT is total 41
Final ER Design
for
the COMPANY Database
42
Alternative (min, max) notation for
Relationship Structural Constraints
• Specifies that each entity e in E participates in at least min and
at most max relationship instances in R at any point in time
• Associate a pair of integer nos (min, max) with each
participation of an entity type E in a relationship type R, where 0
min max and max 1
• min=0 implies partial participation
• min > 0 implies total participation
• Default (no constraint): min = 0, max = n
• Derived from the knowledge of mini-world constraints
• Use either the cardinality ratio/single-line/double- line notation
or the (min, max) notation (The (min, max) notation is more
precise and we will follow this notation for exercises.) 43
Example
(0,1) (1,1)
(1,1) (1,N)
45
Summary of Notation for ER Diagram
46
Check for Other Alternative Diagrammatic Notations for ER Diagrams
Relationships of Higher Degree
• Relationship types:
– degree 2: binary; degree 3: ternary; degree n: n-ary
• Task:
– Differences between binary and higher-degree relationships
– When to choose higher degree or binary relationships
– Constraints on higher-degree relationships
• Constraints are harder to specify for higher-degree
relationships (n > 2) than for binary relationships
• In general, an n-ary relationship is not equivalent to n
binary relationships
– e.g., 3 binary relationships can represent different information
than a single ternary relationship
47
Example of a Ternary Relationship
Instances
SUPPLY (s, j, p)
The SUPPLY Relationship (supplier, project, part)
Instances
CAN_SUPPLY (s, p)
USES (j, p)
SUPPLIES (s, j)
Existence of 3 relationship instances (s, p), (j, p), (s, j) does not necessarily
imply that an instance (s, j, p) exists in the ternary relationship
48
Example: Ternary Relationship Type
What to do now as some DB design tools are based on variations of
the ER model that permit only binary relationships ??
51
Data Modeling Tools
• A number of popular tools that cover conceptual modeling
and mapping into relational schema design.
• Examples:
– Draw.io, Lucidchart, SQuirreL SQL Client, MySQL Workbench,
erwin Data Modeler, ER/Studio, Postico, Navicat, Datagrip, etc.
52
Defining Constraints:
Lets try some problems….
53