ER Model
ER Model
2
Overview of Database Design Process
• Database application
– refer to a particular database, e.g. a BANK database
4
Database Design Process
• Requirements collection
and analysis
– Users’ data and functional
requirements
– Using software engineering
tools, e.g., data flow diagrams)
9
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, sex, 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, sex, birth date, and relationship to the
employee 10
An ER Schema Diagram for the
COMPANY Database
11
Entity-Relationship Model
• Entity:
– Real-world object, concept, or event in the mini-world
that exists and is distinguishable from other objects
• The EMPLOYEE Neena Singh, the Research DEPARTMENT, the
ProductX PROJECT
• Event, plant, president, amendment_5, senate, job etc.
• Entity type/set:
– Collection of entities of the same type that share the
same properties
• For example: set of all employees, companies, trees, holidays
12
Entity-Relationship Model
• Attribute:
– Properties used to describe an entity
• An EMPLOYEE entity may have the attributes Name, SSN, Address,
Sex, BirthDate
• amendment_5 = (number, definition)
– A specific entity will have a value for each of its attributes
• A specific employee entity may have Name = ‘Neena Singh’, SSN =
‘123456789’, Address = ‘731, Pashchim Vihar, New Delhi’, Sex =‘F’,
BirthDate = ‘09-JAN-85’
– Each attribute has a value set (Domain or data type)
associated with it
• Relationship: Association among two or more entity sets
• Relationship type/set: Collection of similar relationships
13
Another Example - “Movie Database”
• Entity:
– Movie, Star
• Attributes:
– Name: “Hritik Roshan” (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)
14
Types of Attributes (1/4)
• Simple and Composite
• Single valued and Multi valued
• Simple and Derived
• Null
15
Types of Attributes (2/4)
• Simple versus Composite
– Simple (or atomic): Each entity has a single atomic value for the
attribute; e.g., SSN or Sex
– Composite: Composition may form a hierarchy where some
components are themselves composite
• e.g. Address(StreetAddress, City, State, Zip) or
Name(FirstName, MiddleName, LastName)
18
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
– For example, SSN of EMPLOYEE
• A key attribute may be composite
– VehicleRegNumber: key of the CAR entity type: (Number, State)
• An entity type may have more than one key
– The CAR entity type may have two keys:
– VehicleIdentificationNumber (Engine no., Chasis no)
– VehicleRegNumber (Number, State), also known as license
plate number
19
Entity Type - Graphical Rep.
• An entity type is displayed in a rectangular box
• Attributes are displayed in ovals
– Each attribute is connected to its entity type
– Components of a composite attribute are connected to the
oval representing the composite attribute
– Each key attribute is underlined
– Multivalued attributes displayed in double ovals
Engine_no • There may be any no. of CAR
entity instances in the entity
set for CAR
• Entity set is the current state
of the entities of that type that
are stored in the database 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
The WORKS_FOR relationship type in which The WORKS_ON relationship type in which
EMPLOYEEs and DEPARTMENTs participate EMPLOYEEs and PROJECTs participate
• Another Example:
Priya Depositor A-102
Customer entity Relationship Account entity
23
Relationship Type Vs Instances
• Relationship Type: is the schema description of a relationship
– Identifies the relationship name, the participating entity types,
and certain relationship constraints
Refined
26
Recursive Relationship Type
• Same participating entity type in
distinct roles
• In SUPERVISION relationship,
Employee participates twice in
two distinct roles:
– supervisor (or boss) role
– supervisee (or subordinate) role 1st role participation labeled with 1 &
2nd role participation labeled with 2
• Each relationship instance
relates two distinct EMPLOYEE
entities:
– One employee in supervisor role
– One employee in supervisee role
27
In ER diagram, need to display role names to distinguish participations
Weak Entity Types
• A weak entity must participate in an identifying relationship
type with an owner or identifying entity type
• Identified by the combination of a partial key of the weak entity
type (underlined with a dashed line), and the particular entity it
is related to in the identifying entity type
– A DEPENDENT entity (weak entity type) identified by
– The dependent’s first name (partial key), and
– The specific EMPLOYEE (identifying entity type) with whom the
dependent is related (DEPENDENT_OF: identifying relationship
type)
• Boxes of weak entities are surrounded with double lines
• Always has a total participation constraint in its identifying
relationship type 28
Constraints on Relationship Types
29
Constraints on Relationship Types
M:N 31
Participation Constraints (1/2)
• Specifies whether the existence of an entity depends on its
being related to another entity via the relationship type
• 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: a company policy states that every employee must work for a
department. Now an employee entity can exist only if it
participates in at least one WORKS_FOR relationship instance.
Participation of employee in WORKS_FOR is total.
– In E-R diagram, it is displayed as a double line 32
Participation Constraints (1/2)
33
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.
• A value of HoursPerWeek depends on a particular (employee,
project) combination
• 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 38
Final ER Design for the COMPANY
Database
• WORKS_FOR
– 1:N relationship type between
DEPARTMENT and EMPLOYEE
– Both participations are total
• CONTROLS
– 1:N relationship type between
DEPARTMENT & PROJECT
– The participation of PROJECT
is total
• WORKS_ON – The participation of
– M:N relationship type with attribute DEPARTMENT is partial
Hours (since a project can have (user’s consultation indicates
several employees working on it) that some deptt may control
– Both participations are total no projects)
39
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 40
Final ER Design
for
the COMPANY Database
41
Alternative (min, max) notation for
Relationship Structural Constraints
• Specified on each participation of an entity type E in a relationship
type R
• 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) 42
Example
(0,1) (1,1)
(1,1) (1,N)
44
Summary of Notation for ER Diagram
45
Defining Constraints: Example
47
UML Class Diagrams
• Represent classes (similar to entity types) as large
rounded boxes with three sections:
– Top section includes entity type (class) name
– Second section includes attributes
– Third section includes class operations (operations are not
in basic ER model)
• Relationships (called associations) represented as lines
connecting the classes
– Other UML terminology also differs from ER terminology
• Used in db design and object-oriented software design
• UML has many other types of diagrams for software
design (see Chapter 12 in Navathe)
48
UML Class Diagram for COMPANY
Database Schema
49
Other Alternative Diagrammatic
Notations for ER Diagrams (1/2)
50
Other Alternative Diagrammatic
Notations for ER Diagrams (1/2)
Instances (s, j, p)
(supplier, project, part)
The SUPPLY Relationship
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
53
How to Represent Higher Degree
Relationships
• If needed, the binary and n-ary relationships can all be included
in the schema design
• Represent relationship as a relationship type of degree n or
break it down into several relationship types of smaller degrees
is tricky
• This decision must be based on the semantics or meaning of the
particular situation being represented
• Some DB design tools are based on variations of the ER model
that permit only binary relationships
– In this case, represent a ternary relationship as a weak entity with
no partial key and with three identifying relationships
54
Example: Ternary Relationship Type
55
Another Ex. of Ternary Relationship Type
OFFERS (i, s, c)
Constraints among the
relationships
59
Data Modeling Tools
• A number of popular tools that cover conceptual modeling
and mapping into relational schema design.
– Examples: ERWin, S- Designer (Enterprise Application Suite), ER-
Studio, etc.
• POSITIVES:
– Serves as documentation of application requirements, easy user
interface - mostly graphics editor support
• NEGATIVES:
– Most tools lack a proper distinct notation for relationships with
relationship attributes
– Mostly represent a relational design in a diagrammatic form
rather than a conceptual ER-based design
(See Chapter 12 for details) 60
Some Automated Database Design Tools
COMPANY TOOL FUNCTIONALITY
Embarcadero ER Studio Database Modeling in ER and IDEF1X
Technologies
DB Artisan Database administration, space and security
management
Oracle Developer Database modeling, application development
2000/Designer 2000
Popkin Software System Architect Data modeling, object modeling, process modeling,
2001 structured analysis/design
Platinum Enterprise Modeling Data, process, and business component modeling
(Computer Suite: Erwin, BPWin,
Associates) Paradigm Plus
Persistence Inc. Pwertier Mapping from O-O to relational model
Rational (IBM) Rational Rose UML Modeling & application generation in C++/JAVA