The ER Model and ER Diagram

by K. Yue

1. Introduction to DB Modeling

What can you do to understand the problem and model it?

  1. Start by asking a lot of questions.
  2. Collect as much documentation as possible.
  3. Study and use the existing system: find out what is currently being used. Use them with the users.
  4. Participate in the work process.
  5. Model, write, and document!
  6. Use your own words and avoid the 'copy and paste' trap. (What is the 'copy and paste' culture?)

Some possible generic questions to ask for modeling.

  1. What are the purposes of the application?
  2. What problems will the application solve? What values will it provide?
  3. What are the boundary and context of the applications?
  4. Who are the users?
  5. Who are the domain experts?
  6. What are the available documentation?
  7. How does the existing system work?
  8. What are the workflow processes of the current system?

Two important options for database modeling:

  1. Entity Relationship (ER) Modeling and Extended ER (EER) Modeling: more specific to relational database.
  2. UML modeling: more general purpose.

Time-out Motivation:

Bureau of Labor Statistics, Computer and Information Technology Job outlook 2016 to 2026:

job outlook

Average annual wage over all jobs in 2017: $37,600. 2016 to 2026 expected overall growth rate is 7%.

2. ER Modeling and ER Diagrams

2. ER Modeling and ER Diagrams

ER Diagrams

Traditional ER notation (Chen's Notation)

Crow-Foot Notations

Example:

Description: A student has a unique student id and can enroll in any number of classes.

For example, Jane Smith, with an student of 3100910, enrolls in the classes 'CSCI 4333.1' and 'CSCI 3352.1'.

ER1_1

ER Modeling is about capturing requirements by ER model. In this example, the assumptions made by the requirements are:

  1. There are students with StudentId, LName and FName.
  2. There are classes with ClassId, Rubric and Number.
  3. A student can enroll in 0 or more classes.
  4. A class can have 0 or more students enrolled in it.

The ER diagram can be used to create entity and relationship instances.

er_note_1

Entity type: Student(StudentId, LName, FName)
Entity (instance): (3100910, 'Smith', 'Jane')
Entity set: {(3100910, 'Smith', 'Jane'), (2001001, 'Johnson', 'John'), (1201021, 'Bajaj', 'Rashid')}

Example:

Consider again:

ER1_1

Note:

Student is an entity type that you can use to instantiate Student objects (entity instances). Examples: we may have the following instances.

S1: Sadegh Davari
S2: Brad Pitts
S3: Stephen Curry

Each student entity represents a student.

Class is an entity type that you can use to instantiate Class entity. Examples: we may have the following instances.

C1: CSCI 4333
C2: CSCI 3388
C3: CINF 3311

Each course entity represents a course.

The relationship Enroll represents association between a student (instance) and a class (instance). The meaning: a student may enroll in a class. For example, we may have:

S1 enrolls in C1
S1 enrolls in C3
S2 enrolls in C1
S3 enrolls in C2
S3 enrolls in C3

The relationship is actually not between two entity types. The relationship is between two entity instances of some types.

In fact, a relationship may be between two entities of the same type.

Example:

Toyu: A drastically simplified university.

ER Diagram (drawn using MySQL Workbench)

toyu_relationship.jpg

Example:

Consider:

ER1_2

The meaning of the relationship "is a prerequisite": one class entity can be a prerequisite of another class entity. For example, we may have:

C1 is a prerequisite of C2
C3 is a prerequisite of C2

Example:

Consider again:

ER1_1

The relationship type Enroll allows a student entity to has an Enroll association with a class entity.

Here are five relationship instances of Enroll:

r1: S1 enrolls in C1
r2: S1 enrolls in C3
r3: S2 enrolls in C1
r4: S3 enrolls in C2
r5: S3 enrolls in C3

Together, they form a relationship set.

Example:

ER_1_1c

ER2_b

workfor_1

Workfor_2

workFor_4

workfor_3

manage_1

Example:

Discuss the ER model for students in an university and its relationship with degree programs (e.g. B.Sc. in CIS, BA in Math, MS in CS, etc).

You may start with:

ProgDeg_1

Example: in Draw.io

er_assoc_entity.png

 

Total participation:

R_Part1

Partial participation:

ER_Part_2

Modeling is about finding the true meanings, assumptions, and requirements and captured them in the selected modeling language.

Example: Chen's suggested 'rule of thumb':

English grammar structure ER structure
Common noun Entity type
Proper noun Entity
Transitive verb Relationship type
Intransitive verb Attribute type
Adjective Attribute for entity
Adverb Attribute for relationship

However, there are so many exceptions.

Example:

Figure 3.11 and Figure 3.12 of Ricardo.

Notes:

Example:

Relationship_1

Note that:

  Entity-Relationship Diagram Relationship Diagram
Rectangle Entity Relation
Link Relationship between entities; can be n-ary. Foreign key relationship between two relations; always binary.