Docsity

ER Modeling: ER Model Basics and Relationships - Prof. Christopher Matthew Jermaine, Study notes of Computer Science

Partial preview of the text

Download ER Modeling: ER Model Basics and Relationships - Prof. Christopher Matthew Jermaine and more Study notes Computer Science in PDF only on Docsity!

Entity Relationship Model

  • Building a software that uses a DB is a 3-step process: (1) Model the part of the real world the DB will store (2) Use that model to obtain DB design (3) Implement the design
  • First 2 weeks of class: -We will focus on first part -Modeling methodology we’ll use: ER Model

ER Model Basics

  • Goal: Model the part of the real world the DB will store
  • ER Model is a graphical (pictorial) model
  • All the world is divided into two classes: -Entities (people, places, things, ideas)

-Relationships (interactions between entities)

Prof Student

Teaches

Cardinalities

  • ER Model has ability to show extent to which instances of entities participate in a relationship:

Mother (^1) Has N Child

“cardinalities”; N stands for “many”

Read this as: “A mother has many children” “A child has one mother”

Many-To-Many Relationships

  • Last relationship was a “one-to-many”
  • Can have “many-to-many”

Prof M Teaches N Student

Note: no good reason to use M and N (could just use N and N) except tradition

Note 2: This example demonstrates importance of context ; if we are talking about just this classroom, Teaches is one-to-many; at UF, it is many-to-many

Total Participation Requirement

  • AKA: “Existence Dependencies”
  • What if every instance of an entity must participate in a rel’n’p?
  • Ex: Every class has to have a prof to teach it
  • Denoted with a bold link:
  • Can you think of other examples?

Prof (^) Teaches Class

Means every class must have a prof to teach it

M N

Attributes

  • Every entity has to have one or more attributes
  • Attributes are characteristics associated with an entity
  • Ex:
  • Ex:

Office

Room #

Building SQ Ft.

Window?

Prof

Name

Fname Lname MI

SSN

Age Rank

Salary

Attributes On Relationships (cont)

  • Here is the correct solution:

Class Taken By Student

Grade

N M

Keys

  • Every entity has one or more attributes that uniquely ID an instance
  • Collectively, these attributes are the key for the entity
  • Ex:
  • Ex:

Office

Room #

Building SQ Ft.

Window?

Prof

Name

Fname Lname MI

SSN

Age Rank

Salary

Weak Entities (cont)

  • Office needs Building to get (part of) its key; Is a weak entity
  • Weak entity indicated with a bold line; identifying relationship is also in bold; any partial key is denoted with a dashed underline

Office

Room #

SQ Ft.

Window?

Building

In Address

#Rooms Age

#Floors

Street Name Number 1

N

To figure out the key for a weak entity, start with all of the attributes in the partial key, then “chase” the IDing relationsip(s)

A Related Question

  • When is a person, place, thing, idea an entity , and when is it just an attribute?
  • First rule of thumb: -If the same attribute shows up in more than one place in your model, make it an entity instead... -Ex: if a bunch of entities all have a “building” attribute, Build- ing should be an entity instead

A Related Question (cont)

  • Third rule of thumb: -If an entity is related to only one other entity, and it is very sim- ple or the relationship is a one-to-one, then make it an attribute instead -Ex: A prof’s rank should not be an entity, since it is simple (just a word), and it is not attached to any other entities

Inheritance

  • Say we have different types of people in our model: students, staff, profs
  • And they share a lot of characteristics
  • Use inheritance to clean up the model:

Person

Name

Fname Lname SSN MI

Age

Student Prof

D

Staff

Grad Date Rank

Salary Job Desc.

So, all people have an SSN, Age, Name, and a home town, but only Profs have a Sal- ary and Rank

“D” means that a Per- son can only be a Stu- dent, a Staff, or a Prof, never more than one

City (^) From (^1) N

Inheritance (cont)

  • A bold line (existence dep) coming out of the superclass means that an instance of the superclass must also have a corresponding instance in the subclass

Person

Name

Fname Lname SSN MI

Age

Student Prof

D

Staff

Grad Date Rank

Salary Job Desc.

If we are modeling a university, this means that a Person has to be either a Student, a Prof, or on the Staff; there are no generic “People” who are not in a sub- class

Union-Type Superclasses

  • Say you have a massive inheritance hierarchy:
  • And every entity in the hierarchy has two distinct subtypes: Man and Woman
  • To show this, we could simply subclass every leaf node in the hierarchy into Man and Woman... a big mess!
  • Or, use the Union superclass