0% found this document useful (0 votes)
5 views

7. Data Modeling Using ER Model

Uploaded by

mahammaryam82
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

7. Data Modeling Using ER Model

Uploaded by

mahammaryam82
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

DATA MODELING USING

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

 Weak Entity Types


 Strong Entity Type
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, …

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.

 The CAR entity type may have two keys:


 VehicleId (popularly called VIN)
 VehicleTagNumber (Number, State), aka license plate

number.
 Each key is underlined

22
ENTITY TYPE CAR WITH TWO KEYS
AND A CORRESPONDING ENTITY
SET

Entity set is the


current state of
the entities that
is stored in the
database

23
INITIAL DESIGN OF ENTITY TYPES:
EMPLOYEE, DEPARTMENT, PROJECT,
DEPENDENT

Entity types in the


COMPANY database:
DEPARTMENT
PROJECT
EMPLOYEE
DEPENDENT

24
REFINING THE INITIAL DESIGN BY
INTRODUCING RELATIONSHIPS
 Some aspects in the requirements will be
represented as relationships

 ER model has three main concepts:


 Entities(and their entity types and entity sets)
 Attributes (simple, composite, multivalued)
 Relationships (and their relationship types and
relationship sets)

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)

 Existence Dependency Constraint (specifies


minimum participation) (also called participation
constraint)
 zero (optional participation, not existence-dependent)
 one or more (mandatory participation, existence-

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-

 Participation constraints define the least


number of relationship instances in which an
entity must compulsorily participate.
 There are two types of participation

constraints-
TOTAL PARTICIPATION-

 It specifies that each entity in the entity set


must compulsorily participate in at least one
relationship instance in that relationship set.
 That is why, it is also called as mandatory

participation.
 Total participation is represented using a

double line between the entity set and


relationship set.
EXAMPLE

 Double line between the entity set “Student”


and relationship set “Enrolled in” signifies
total participation.
 It specifies that each student must be

enrolled in at least one course.


PARTIAL PARTICIPATION-

 It specifies that each entity in the entity set


may or may not participate in the
relationship instance in that relationship set.
 That is why, it is also called as optional

participation.
 Partial participation is represented using a

single line between the entity set and


relationship set.
EXAMPLE

 Single line between the entity set “Course”


and relationship set “Enrolled in” signifies
partial participation.
 It specifies that there might exist some

courses for which no enrollments are made.


RELATIONSHIP BETWEEN CARDINALITY AND
PARTICIPATION CONSTRAINTS-

 Minimum cardinality tells whether the


participation is partial or total.
 If minimum cardinality = 0, then it signifies

partial participation.
 If minimum cardinality = 1, then it signifies

total participation.
 Maximum cardinality tells the maximum

number of entities that participates in a


relationship set.
ER DIAGRAM – RELATIONSHIP TYPES ARE:
WORKS_FOR, MANAGES, WORKS_ON, CONTROLS, SUPERVISION, DEPENDENTS_OF

50
STEPS TO DRAW AN ER DIAGRAM
 Get problem description
 Define Entities

 Add Attributes

 Specify Key, multiple, composite attributes

 Add Relations

 Specify Cardinality, total/partial 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

ternary and of degree n are called n-ary


 Constraints are harder to specify for higher-

degree relationships (n > 2) than for binary


relationships

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

another way of displaying ER concepts

60
OTHER ALTERNATIVE
DIAGRAMMATIC NOTATIONS

61

You might also like