7. Data Modeling Using ER Model
7. 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
A particular object belonging to a particular
entity type.
For Example:
ENTITY SET
A group of entity instances of a particular
entity type is called an entity set.
For example, all employees of an
organization form an entity set. Like all
students, all courses, all of them form entity
set of different entity types.
ENTITY INSTANCE & SET
A particular object belonging to a particular
entity type
Entity Type: Employee
Entity Instance: M. Sharif
Entity Set: All employees
CLASSIFICATION OF ENTITY
TYPES
Attributes
They are properties used to describe an entity.
Each attribute has a data type
E.g. integer, string, subrange, enumerated
type, …
13
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
16
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
17
EXAMPLE OF A COMPOSITE
ATTRIBUTE
18
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.
21
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
22
ENTITY TYPE CAR WITH TWO KEYS
AND A CORRESPONDING ENTITY
SET
23
INITIAL DESIGN OF ENTITY TYPES:
EMPLOYEE, DEPARTMENT, PROJECT,
DEPENDENT
24
REFINING THE INITIAL DESIGN BY
INTRODUCING RELATIONSHIPS
Some aspects in the requirements will be
represented as relationships
25
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 26
relationships.
RELATIONSHIP INSTANCES OF THE WORKS_FOR
RELATIONSHIP BETWEEN EMPLOYEE AND DEPARTMENT
27
RELATIONSHIP INSTANCES OF THE WORKS_ON
RELATIONSHIP BETWEEN EMPLOYEE AND PROJECT
28
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
30
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)
33
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)
37
TYPES OF CARDINALITIES
MANY-TO-ONE (N:1) RELATIONSHIP
39
MANY-TO-MANY (M:N) RELATIONSHIP
40
MINIMUM CARDINALITY
Determines whether the link is compulsory or
optional
Important, since it effects the
implementation
CARDINALITY EXAMPLE(CROW'S
FOOT
NOTATION)
OTHER NOTATIONS(CHEN )
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
50
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
Draw E\R model for the Publishing company database with the
following requirements
A publishing company produces books on various subjects. The books are
written by authors who specialize in one particular subject. The company
employs editors who, not necessarily being specialists in a particular area,
each take sole responsibility for editing one or more book publications. Every
book require some items for publication. These items supplied by suppliers.
One supplier can supply many items. Shop owner buys books from the
publisher . Shop owner can buy many books but one book can be bought by
one shop owner only. Books are uniquely identified byBookid.
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
Default(no constraint): min=0, max=n
Must have min max, min 0, max 1
Derived from the knowledge of mini-world constraints
54
MIN, MAX - NOTATION
55
NOTATION FOR ER DIAGRAMS
56
RELATIONSHIPS OF HIGHER DEGREE
Relationship types of degree 2 are called
binary
Relationship types of degree 3 are called
57
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
58
ALTERNATIVE DIAGRAMMATIC
NOTATION
ER diagrams is one popular example for
displaying database schemas
UML class diagrams is representative of
60
OTHER ALTERNATIVE
DIAGRAMMATIC NOTATIONS
61