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

Lecture 04 Data - Modeling - Using - ER - Model

Uploaded by

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

Lecture 04 Data - Modeling - Using - ER - Model

Uploaded by

aashir.aftab01
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 70

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 & 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.

 The CAR entity type may have two keys:


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

number.
 Each key is underlined

20
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

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

Entity types in the


COMPANY database:
DEPARTMENT
PROJECT
EMPLOYEE
DEPENDENT

22
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)

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)

 Existence Dependency Constraint (specifies


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

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-

 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

48
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 1
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 by Bookid.
ERD
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

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

ternary and of degree n are called n-ary


 Constraints are harder to specify for higher-

degree relationships (n > 2) than for binary


relationships

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

 For example, the TAUGHT_DURING binary


relationship can be derived from the ternary
relationship OFFERS (based on the meaning
of the relationships)

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

 (min, max) constraints can be displayed on the


edges – however, they do not fully describe the
constraints

60
 In general, both (min, max) and 1, M, or N are
needed to describe fully the constraints
CARDINALITY FOR TERNARY
RELATIONSHIP

Constraint: For a particular project-part combination, only one


supplier will be used (only one supplier supplies a particular part
to a particular project).

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

another way of displaying ER concepts

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

 Using ER in step-by-step conceptual schema

design for the COMPANY database


 ER Diagrams - Notation

 Alternative Notations – UML class diagrams,

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

You might also like