ER Design (1) Entity-Relationship (ER) Model Elements in a - - PDF document

er design 1 entity relationship er model
SMART_READER_LITE
LIVE PREVIEW

ER Design (1) Entity-Relationship (ER) Model Elements in a - - PDF document

ER Design (1) Entity-Relationship (ER) Model Elements in a database: data entries Data entries represent Entities: data objects, e.g., students, courses, and instructors Relationships among entities: students take courses,


slide-1
SLIDE 1

ER Design (1)

slide-2
SLIDE 2

CMPT 354: Database I -- ER Design (1) 2

Entity-Relationship (ER) Model

  • Elements in a database: data entries
  • Data entries represent

– Entities: data objects, e.g., students, courses, and instructors – Relationships among entities: students take courses, instructors teach courses

  • ER model: modeling data using entities and

relationships

slide-3
SLIDE 3

CMPT 354: Database I -- ER Design (1) 3

E-R Diagrams

  • Rectangles represent entity sets
  • Diamonds represent relationship sets
  • Lines link attributes to entity sets and entity

sets to relationship sets

  • Ellipses represent attributes

– Double ellipses represent multivalued attributes – Dashed ellipses denote derived attributes

  • Underline indicates primary key attributes
slide-4
SLIDE 4

CMPT 354: Database I -- ER Design (1) 4

Example

slide-5
SLIDE 5

CMPT 354: Database I -- ER Design (1) 5

Involving One Entity Set Twice

  • Ann and Bob are employees in

SmallCompany

– Two entities in entity set employee

  • Ann is Bob’s supervisor

– (Ann, Bob) ∈ supervision – Relationship set supervision involves entity set employee twice – How can we call the first employee and the second employee in a supervision relationship?

slide-6
SLIDE 6

CMPT 354: Database I -- ER Design (1) 6

Roles

  • The labels “manager” and “worker” are called

roles; they specify how employee entities interact via the works_for relationship set

  • Role labels are optional, and are used to clarify

semantics of the relationship

slide-7
SLIDE 7

CMPT 354: Database I -- ER Design (1) 7

Keys and Mapping Cardinality

  • One to one relationship set

– Use a candidate key in either entity set – University-president(university, president)

  • Many to one relationship set

– Use a candidate key in the one side entity set – Teaching (instructor, courses)

  • Many to many relationship set

– Use a candidate key in each participating entity set – Take-course(student, course)

  • How to annotate cardinality constraints in ER

diagram?

slide-8
SLIDE 8

CMPT 354: Database I -- ER Design (1) 8

Cardinality Constraints

  • Drawing either a directed line (→), signifying

“one,” or an undirected line (—), signifying “many,” between the relationship set and the entity set.

  • One-to-one relationship

– Each customer can have at most one loan – Each loan is associated with at most one customer

slide-9
SLIDE 9

CMPT 354: Database I -- ER Design (1) 9

One-To-Many Relationship

  • In the one-to-many relationship a loan is

associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower

slide-10
SLIDE 10

CMPT 354: Database I -- ER Design (1) 10

Many-To-One Relationships

  • In a many-to-one relationship a loan is

associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower

slide-11
SLIDE 11

CMPT 354: Database I -- ER Design (1) 11

Many-To-Many Relationship

  • A customer is associated with several

(possibly 0) loans via borrower

  • A loan is associated with several (possibly

0) customers via borrower

slide-12
SLIDE 12

CMPT 354: Database I -- ER Design (1) 12

Participation of an Entity Set

  • Total participation (indicated by double line): every entity in

the entity set participates in at least one relationship in the relationship set

– E.g., participation of loan in borrower is total: every loan must have a customer associated to it via borrower

  • Partial participation: some entities may not participate in

any relationship in the relationship set

– Example: participation of customer in borrower is partial

slide-13
SLIDE 13

CMPT 354: Database I -- ER Design (1) 13

Entity Sets or Attributes

  • The structure of

the enterprise being modeled

  • The semantics

associated with the attribute in question

slide-14
SLIDE 14

CMPT 354: Database I -- ER Design (1) 14

Entity Sets or Relationship Sets

  • Designate a relationship set to describe an

action that occurs between entities

slide-15
SLIDE 15

CMPT 354: Database I -- ER Design (1) 15

A Ternary Relationship

slide-16
SLIDE 16

CMPT 354: Database I -- ER Design (1) 16

Cardinality Constraints

  • At most one arrow out of a ternary (or greater

degree) relationship to indicate a cardinality constraint

– An arrow from works_on to job indicates each employee works on at most one job at any branch

  • Confusion with more than one arrow

– Each A entity is associated with a unique entity from B and C (i.e., a combination of B and C), or – Each pair of entities from (A, B) is associated with a unique C entity, and each pair (A, C) is associated with a unique B

A B C

slide-17
SLIDE 17

CMPT 354: Database I -- ER Design (1) 17

Binary vs. Non-Binary Relationships

  • Some non-binary relationships may be

better represented using binary relationships

– E.g. A ternary relationship parents, relating a child to his/her father and mother, is best replaced by two binary relationships, father and mother

  • Using two binary relationships allows partial

information (e.g. only mother being know)

  • But there are some relationships that are

naturally non-binary, e.g., works_on

slide-18
SLIDE 18

CMPT 354: Database I -- ER Design (1) 18

Converting Non-Binary Relationships

  • A non-binary relationship can be

represented using binary relationships by creating an artificial entity set

– Replace R between entity sets A, B and C by an entity set E, and three relationship sets:

slide-19
SLIDE 19

CMPT 354: Database I -- ER Design (1) 19

Summary

  • Roles
  • Cardinality constraints
  • Participation
  • Choice of entity sets attributes, or

relationship sets

  • Binary and non-binary relationships
slide-20
SLIDE 20

CMPT 354: Database I -- ER Design (1) 20

To-Do-List

  • Can you think about some situations where

the facilities of ER design we have so far are still insufficient to model the application data?