Lecture 04 Data - Modeling - Using - ER - Model
Lecture 04 Data - Modeling - Using - ER - Model
THE ENTITY-RELATIONSHIP
MODEL
1
MAJOR COMPONENTS
Entities
Attributes
Relationships
ENTITY
Term used to mean three different meanings
Entity type
Entity instance
Entity set
ENTITY TYPE
A name/label assigned to items/objects that
exist in an environment and that have similar
properties
It could be person, place, event or even
concept
ENTITY INSTANCE & SET
A particular object belonging to a particular
entity type
Entity Type: Employee
Entity Instance: M. Sharif
Entity Set: All employees
TYPES OF ENTITY TYPES
Entity types can be classified into
regular/strong/independent ETs or
weak/dependent ETs
WEAK ENTITY TYPES
An entity type whose instances cannot exist
without being linked with instances of some
other entity type, i.e., they cannot exist
independently
STRONG ENTITY TYPE
A strong/regular entity type is the one whose
instances can exist independently, i.e.,
without being linked to other instances
Strong ETs have their own identity
NAMING ENTITY TYPES
Singular noun recommended
Organization specific names
Write in capitals
Abbreviations can be used, be consistent
SYMBOLS
ER MODEL CONCEPTS
Attributes
They are properties used to describe an entity.
Each attribute has a data type
E.g. integer, string, subrange, enumerated
type, …
11
SYMBOLS FOR ATTRIBUTES
Each represented as an oval, linked with an
ET symbol
TYPES OF ATTRIBUTES
Single vs composite
Single valued vs multi-valued
Stored vs derived
Complex attribute
TYPES OF ATTRIBUTES
Simple
Each entity has a single atomic value for the
attribute. For example, SSN or Sex.
Composite
The attribute is composed of several components.
For example:
Address(House#, Street, City, State, ZipCode, Country),
Name(FirstName, MiddleName, LastName).
Multi-valued
An entity may have multiple values for that attribute.
For example:
PreviousDegrees of a STUDENT.
Stored and Derived
14
TYPES OF ATTRIBUTES
Complex attribute - The composite and multi-
valued attributes may be nested arbitrarily to
any number of levels,
Forexample, 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
15
EXAMPLE OF A COMPOSITE
ATTRIBUTE
16
SYMBOLS FOR ATTRIBUTES
EXAMPLE
ENTITY TYPES AND KEY
ATTRIBUTES
Entities with the same basic attributes are
grouped into an Entity type.
For example, the entity type EMPLOYEE
and PROJECT.
Key attribute
For example, SSN of EMPLOYEE.
19
KEY ATTRIBUTES
A key attribute may be composite.
VehicleTagNumber is a key of the CAR
entity type with components (Number,
State).
An entity type may have more than one key.
number.
Each key is underlined
20
ENTITY TYPE CAR WITH TWO KEYS
AND A CORRESPONDING ENTITY
SET
21
INITIAL DESIGN OF ENTITY TYPES:
EMPLOYEE, DEPARTMENT, PROJECT,
DEPENDENT
22
REFINING THE INITIAL DESIGN BY
INTRODUCING RELATIONSHIPS
Some aspects in the requirements will be
represented as relationships
23
RELATIONSHIPS
A relationship relates two or more distinct
entities with a specific meaning.
For example, EMPLOYEE John works on the
ProductX PROJECT,
EMPLOYEE Franklin manages the Research
DEPARTMENT.
Relationships of the same type are grouped
into a relationship type.
Degree of a relationship type is the no of
participating entity types.
Both MANAGES and WORKS_ON are binary 24
relationships.
RELATIONSHIP INSTANCES OF THE WORKS_FOR
RELATIONSHIP BETWEEN EMPLOYEE AND DEPARTMENT
25
RELATIONSHIP INSTANCES OF THE WORKS_ON
RELATIONSHIP BETWEEN EMPLOYEE AND PROJECT
26
SYMBOL
RELATIONSHIP TYPE VS.
RELATIONSHIP SET
Relationship Set:
A relationship set is a set of relationships of
same type.
Relationship Type:
Identifies the relationship name and the
participating entity types
Also identifies certain relationship constraints
28
TYPES OF RELATIONSHIP SET
The number of entity sets that participate in
a relationship set is termed as the degree of
that relationship set. Thus
UNARY RELATIONSHIP
An ET linked with itself, also called recursive
relationship
Example Roommate, where STUDENT is
linked with STUDENT
COMPANY DATABASE: RELATIONSHIPS
Six relationship types are identified
All are binary relationships( degree 2)
WORKS_FOR (between EMPLOYEE, DEPARTMENT)
MANAGES ( between EMPLOYEE, DEPARTMENT)
CONTROLS (between DEPARTMENT, PROJECT)
WORKS_ON (between EMPLOYEE, PROJECT)
SUPERVISION (between EMPLOYEE (as subordinate),
EMPLOYEE (as supervisor))
DEPENDENTS_OF (between EMPLOYEE, DEPENDENT)
31
EXAMPLE
ATTRIBUTES OF THE
RELATIONSHIPS
The key ( combination of key STD+Course )
The relationships can have their descriptive
attributes
Where to place
TERNARY RELATIONSHIPS
One that involves three entity types
STUDENT-CLASS-FACULTY
CONSTRAINTS ON RELATIONSHIPS
TYPE
Constraints on Relationship Types (ratio
constraints)
Cardinality Ratio (specifies maximum participation)
One-to-one (1:1)
One-to-many (1:N) or Many-to-one (N:1)
Many-to-many (M:N)
dependent)
35
TYPES OF CARDINALITIES
MANY-TO-ONE (N:1) RELATIONSHIP
37
MANY-TO-MANY (M:N) RELATIONSHIP
38
MINIMUM CARDINALITY
Determines whether the link is compulsory or
optional
Important, since it effects the
implementation
CARDINALITY EXAMPLE
OTHER NOTATIONS
PARTICIPATION CONSTRAINTS-
constraints-
TOTAL PARTICIPATION-
participation.
Total participation is represented using a
participation.
Partial participation is represented using a
partial participation.
If minimum cardinality = 1, then it signifies
total participation.
Maximum cardinality tells the maximum
48
STEPS TO DRAW AN ER DIAGRAM
Get problem description
Define Entities
Add Attributes
Add Relations
Iterate
STEPS TO DRAW AN ER DIAGRAM
Essential to further design, but often given
little care:
Is an entity a weak entity (key?)
Multivalued attributes
Derived attribute
Total/partial participation
Cardinality ratio
PROBLEM 1
Draw E\R model for the Publishing company database with the
following requirements
53
MIN, MAX - NOTATION
54
NOTATION FOR ER DIAGRAMS
55
RELATIONSHIPS OF HIGHER DEGREE
Relationship types of degree 2 are called
binary
Relationship types of degree 3 are called
56
N-ARY RELATIONSHIPS (N > 2)
Three binary relationships represents
different information than a single ternary
relationship
In some cases, a ternary relationship can be
represented as a weak
57
EXAMPLE 3 OF A TERNARY
RELATIONSHIP
58
N-ARY RELATIONSHIPS (N > 2)
If a particular binary relationship can be
derived from a higher-degree relationship at
all times, then it is redundant
59
DISPLAYING CONSTRAINTS ON
HIGHER-DEGREE RELATIONSHIPS
Displaying a 1, M, or N indicates
1 indicates that an entity can participate in at
most one relationship instance that has a
particular combination of the other participating
entities
M or N indicates no constraint
60
In general, both (min, max) and 1, M, or N are
needed to describe fully the constraints
CARDINALITY FOR TERNARY
RELATIONSHIP
61
DISPLAYING CONSTRAINTS ON HIGHER-
DEGREE RELATIONSHIPS
ALTERNATIVE DIAGRAMMATIC
NOTATION
ER diagrams is one popular example for
displaying database schemas
UML class diagrams is representative of
63
UML CLASS DIAGRAMS
Represent classes (similar to entity
types) as large boxes with three
sections:
Top section includes entity type (class)
name
Second section includes attributes
Third section includes class operations
(operations are not specified in ER model)
Composite attribute is modeled as a
structured domain
Name of EMPLOYEE
Multivalued attribute is modeled as a
separate class
64
LOCATION class
UML CLASS DIAGRAMS
Relationship types are called associations in
UML
Relationship instances are called links
Relationships are represented as lines
connecting the classes
The (min, max) notation is used to specify
relationship constraints (multiplicities)
multiplicities are placed on the opposite
ends of the relationship
A recursive relationship is called a reflexive
association in UML
Weak entities can be modeled using the
construct called qualified association
UML CLASS DIAGRAM FOR
COMPANY DATABASE SCHEMA
Qualified
association
for weal
entity
66
OTHER ALTERNATIVE
DIAGRAMMATIC NOTATIONS
67
CHAPTER SUMMARY
ER Model Concepts: Entities, attributes,
relationships
Constraints in the ER model
others
68
HW 1
Draw E\R model for the university database with the following
requirements
a) The university keeps track of each student's name, rollno, SSN, current
address and phone, permanent address and phone, birthdate, sex, class
(freshman, sophomore, ..., graduate), major department, minor
department (if any), and degree program (B.A., B.S., ..., Ph.D.). Some
user applications need to refer to the city, state, and zip of the
student's permanent address, and to the student's last name. Both SSN
and Rollno have unique values for each student.
b) Each department is described by a name, code, office number, office
phone, and college. Both name and code have unique values for each
department.
c) Each course has a course name, description, course number, number of
semester hours, level, and offering department. The value of course
number is unique for each course.
d) Each section has an instructor, semester, year, course, and section
number. The section number distinguishes different sections of the
same course that are taught during the same semester/year; its values
are 1, 2, 3, ...; up to the number of sections taught during each
semester.
e) A grade report has a student, section, letter grade, and numeric grade
HW 2: ER FOR NOTOWN RECORDS
Each musician has an SSN, name, address, phone. Poor
musicians often share the same address, and no address has
more than one phone.
Each instrument that is used in songs recorded at Notown
has a name (e.g., guitar, flute) and a musical key (e.g., C, B-
flat).
Each album has a title, a copyright date, a format (e.g., CD
or MC), and an album identifier.
Each song recorded at Notown has a title and an author.
Each musician may play several instruments, and an
instrument may be played by several musicians.
Each album has a number of songs on it, but no song may
appear on more than one album.
Each song is performed by one or more musicians, and a
musician may perform a number of songs.
Each album has exactly one musician who acts as its
producer. A musician may produce several albums, of