My Chap 3 ER MODEL Navathe
My Chap 3 ER MODEL Navathe
Slide 3- 1
• Overview of Database Design Process
• Example Database Application (COMPANY)
• ER Model Concepts
• Entities and Attributes
• Entity Types, Value Sets, and Key Attributes
• Relationships and Relationship Types
• Weak Entity Types
• Roles and Attributes in Relationship Types
• ER Diagrams - Notation
• ER Diagram for COMPANY Schema
Slide 3- 2
• Two main activities:
• Database design
• Applications design
Slide 3- 3
Slide 3- 4
• We need to create a database schema design based on the
following (simplified) requirements of the COMPANY
Database:
• The company is organized into DEPARTMENTs.
• Each department has a name, number and an employee who
manages the department.
Slide 3- 8
• Simple
• Each entity has a single atomic value for the attribute. For
example, SSN or Sex.
• Composite
• They can be divided into smaller subparts,which represent
basic attributes.
• The attribute may be composed of several components.
• For example:
• Address(Apt#, House#, Street, City, State, ZipCode,
Country), or
• Name(FirstName, MiddleName, LastName).
• Composition may form a hierarchy where some
components are themselves composite.
Slide 3- 9
Slide 3- 10
• SINGLE VALUED VS MULTIVALUED Attributes
• Single valued : Ex : AGE
• Multivalued : An entity may have multiple values for that attribute.
• For example, Color of a CAR or Previous Degrees of a STUDENT.
• Denoted as {Color} or {Previous Degrees}
• STORED Vs DERIVED ATTRIBUTES
• NULL VALUES
• COMPLEX ATTRIBUTES
In general, composite and multi-valued attributes may be nested arbitrarily to
any number of levels, although this is rare.
• For example, PreviousDegrees of a STUDENT is a composite multi-valued
attribute denoted by {PreviousDegrees (College, Year, Degree, Field)}
• Multiple PreviousDegrees values can exist
• Each has four subcomponent attributes:
• College, Year, Degree, Field Slide 3- 11
• Entities with the same basic attributes, are grouped into an
entity type.
• For example, the entity type EMPLOYEE and PROJECT.
Slide 3- 12
• A key attribute may be composite.
• If a set of attributes satisfy this uniqueness property……
Composite Key.
• EX : Vehicle_Reg_no is a key of the CAR entity
type with components (Number, State).
• An entity type may have more than one key.
• The CAR entity type may have two keys:
• Vehicle Identification Number (popularly called VIN)
• Vehicle_Reg_No (Number, State), ie license plate number.
• Each key is underlined inside the oval.
Slide 3- 13
• In ER diagrams, an entity type is displayed in a rectangular box
Slide 3- 14
Slide 3- 15
• Each entity type will have a collection of entities stored in the
database
• Called the entity set
• Previous slide shows three CAR entity instances in the entity set
for CAR
• Same name (CAR) used to refer to both the entity type and the
entity set
• Entity set is the current state of the entities of that type that are
stored in the database
Slide 3- 16
• Based on the requirements listed, we can identify four initial
entity types in the COMPANY database:
• DEPARTMENT
• PROJECT
• EMPLOYEE
• DEPENDENT
Slide 3- 17
Slide 3- 18
• The initial design is typically not complete .
Slide 3- 19
• We introduce relationship concepts next
Slide 3- 20
• A relationship relates two or more distinct entities with a
specific meaning.
• For example, EMPLOYEE Ruby works on the ProductX
PROJECT,
• EMPLOYEE Franklin manages the Research DEPARTMENT.
In ER diagrams …..
These relationship types are depicted by diamond shaped boxes
which are connected by straight lines to rectangular boxes
representing the participating entity types.
Slide 3- 23
Slide 3- 24
• Previous figures displayed the relationship sets
• Each instance in the set relates individual participating
entities – one from each participating entity type
• In ER diagrams, we represent the relationship type as
follows:
• Diamond-shaped box is used to display a relationship type
• Connected to the participating entity types via straight lines
Slide 3- 25
Degree of a Relationship type : The degree of a relationship
type is the number of participating entity types. WORKS_FOR
relationship is of degree 2.
• Degree 2 is called Binary .
• Degree 3 is called Ternary .
RELATIONSHIPS shown as ATTRIBUTES
The ex of WORKS_FOR relationship type…..
NOTE ………… We can think of an attribute called Department
in the entity type EMPLOYEE.
This itself will tell about emp e1 WORKS_FOR dept D1.
Slide 3- 26
• Each entity plays a particular role In a relationship.
• Role name signifies the role that a participating entity from entity
type plays.
• Ex: Works-For relationship…..
Employee plays the role of employee or worker, and
Department plays the role of dept or employer.
Ex of 1: N Relationship :-
In the Works_For relationship type,
Employee : Department is of cardinality ratio N : 1
Each dept can be related to ‘N’ employees; but an employee can
be related to (work for) only ONE department.
Ex of 1:1 Relationship :-
In the MANAGES relationship type ,
Employee : Department is of cardinality ratio 1:1 Slide 3- 31
The MANAGES relationship goes by a real-world constraint that….
at any point in time — an employee can manage one department
only, and a department can have one manager only.
Ex of M:N relationship :-
• In the Works_on relationship type,
Employee : Project is of cardinality ratio M:N
Each employee can work_on ‘N’ projects ;
and a project can have ‘M’ number of employees.
Slide 3- 32
• The participation constraint specifies whether the existence of an
entity depends on its being related to another entity via the
relationship type.
Slide 3- 33
If a company policy states that “ every employee must work for a
department, “
An employee entity can exist only if it participates in
atleast ( minimum of ) ONE Works_For relationship instance.
Slide 3- 36
• CONTROLS : A 1 : N relationship type between
DEPARTMENT and PROJECT .
DEPARTMENT participation is Partial.
PROJECT participation is Total .
Slide 3- 37
• SUPERVISION : A 1 : N relationship type between
EMPLOYEE ( in supervisor Role ) and EMPLOYEE ( in
supervisee Role ) .
EMPLOYEE ( Supervisor Role) participation is
Partial.
EMPLOYEE ( Supervisee Role) participation is
Partial .
Slide 3- 38
• DEPENDENTS _ OF : A 1 : N relationship type between
EMPLOYEE and DEPENDENT .
EMPLOYEE participation is Partial.
DEPENDENT participation is Total .
Slide 3- 39
• By examining the requirements, six relationship types are
identified
• All are binary relationships( degree 2)
• Listed below with their participating entity types:
Slide 3- 42
• An relationship type whose with the same participating entity type in
distinct roles
• Example: The SUPERVISION relationship
Slide 3- 44
• Constraints on Relationship Types
• Constraints limit the possible combinations of entities that may
participate in the corresponding relationship .
• These constraints are determined from the real world situation.
• For ex:--
If the company has a rule that each employee MUST work for
exactly one department, then we can describe this constraint in the
schema.
TWO main types of RELATIONSHIP CONSTRAINTS …..
Slide 3- 45
Cardinality Ratio : It specifies the maximum no of relationship
instances that an entity can participate in.
Ex 1 : In WORKS_FOR relationship type,
EMPLOYEE : DEPARTMENT is of Cardinality ratio N : 1
An employee can be related to 1 department, but one
department can be related to any number of employees .
Slide 3- 47
• This constraint specifies whether the EXISTENCE of an ENTITY
depends on its being related to another entity via a relationship
type .
• This constraint specifies the minimum no of relationship
instances that each Entity can participate in , and is sometimes
called the minimum cardinality constraint.
TWO TYPES : --
• Total Participation
• Partial Participation
Slide 3- 48
Slide 3- 49
Slide 3- 50
Slide 3- 51
• A relationship type can have attributes:
• For example, 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
• Most relationship attributes are used with M:N relationships
• In 1:N relationships, they can be transferred to the entity type on the
N-side of the relationship
Slide 3- 52
Slide 3- 53
• Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or
M:N
• Shown by placing appropriate numbers on the relationship edges.
• Participation constraint (on each participating entity type): total
(called existence dependency) or partial.
• Total shown by double line, partial by single line.
• NOTE: These are easy to specify for Binary Relationship Types.
Slide 3- 54
• 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
• Default(no constraint): min=0, max=n (signifying no limit)
• Must have minmax, min0, max 1
• Derived from the knowledge of mini-world constraints
• Examples:
• A department has exactly one manager and an employee can manage at
most one department.
• Specify (0,1) for participation of EMPLOYEE in MANAGES
• Specify (1,1) for participation of DEPARTMENT in MANAGES
• An employee can work for exactly one department but a department can
have any number of employees.
• Specify (1,1) for participation of EMPLOYEE in WORKS_FOR
• Specify (1,n) for participation of DEPARTMENT in WORKS_FOR
Slide 3- 55
Read the min,max numbers next to the entity
type and looking away from the entity type
Slide 3- 56
Slide 3- 57
• ER diagrams is one popular example for displaying database
schemas
• Many other notations exist in the literature and in various
database design and modeling tools
• Appendix A illustrates some of the alternative notations that
have been used
• UML class diagrams is representative of another way of
displaying ER concepts that is used in several commercial design
tools
Slide 3- 58
Slide 3- 59