0% found this document useful (0 votes)
34 views60 pages

Lecture 08 Erd

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views60 pages

Lecture 08 Erd

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Entity-Relationship (ER) Diagrams

Lecture 8

Entity-Relationship (ER) Diagrams

October 17, 2020 1


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Outline
1. Context
– Design & Implementation Process
2. Goals of Conceptual Design
3. Entity-Relationship (ER) Model
4. One ER Diagrammatic Notation
5. Requirements Elicitation
6. Approaches to Conceptual Design

Entity-Relationship (ER) Diagrams

October 17, 2020 2


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Database Design and Implementation Process

Entity-Relationship (ER) Diagrams

October 17, 2020 3


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Goal of Conceptual Design


Description of data requirements that is…

Comprehensive
• Entity types, relationships, and constraints
• Sanity check of data & functional requirements
• Reference for [unit/integration] testing/analysis

Concise/High-level
• Easy to understand technically
• Easy to communicate with non-technical users
• Facilitates focus on data (vs. storage/implementation details)

Algorithmically Transformable
• Improves application development efficiency, reduces errors

Entity-Relationship (ER) Diagrams

October 17, 2020 4


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Entity-Relationship (ER) Model


Entity
• Thing in the real world

Attribute
• Property of an entity
• Most of what we store in the database

Relationship
• Association between sets of entities
• Possibly with attribute(s)

Entity-Relationship (ER) Diagrams

October 17, 2020 5


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

ER Diagrams
• Graphical depiction
of an ER model
• Many notations, this
class…
All cars have a year, age, make, model,
registration (unique), vehicle number
(vin; unique), some number of colors…

Specialization/Generalization

Suggestion: https://www.diagrams.net

Entity-Relationship (ER) Diagrams

October 17, 2020 6


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Entity Sets
Set of entities that have Make Year Model
the same attributes

All cars have a year, CAR


make, and model.

Entity-Relationship (ER) Diagrams

October 17, 2020 7


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Composite Attributes
Can be subdivided into Make Year Model
smaller subparts

All cars have a year, CAR


make, model, and
registration. Registration

State Number

Entity-Relationship (ER) Diagrams

October 17, 2020 8


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Multivalued Attributes
Can take some number Make Year Model
of values.

All cars have a year, Color CAR


make, model,
registration, and some Registration
number of colors.
State Number

Entity-Relationship (ER) Diagrams

October 17, 2020 9


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Key Attributes
The value uniquely Make Year Model
identifies each entity

All cars have a year, Color CAR VIN

make, model,
registration (unique), Registration
vehicle number (vin;
unique), some number State Number
of colors.

Entity-Relationship (ER) Diagrams

October 17, 2020 10


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Potential Pitfall
• In relational schema, underlining multiple
attributes indicates that for all rows, the
combination is unique (primary)

• In ERDs, underlining multiple attributes


indicates that each individually can
uniquely identify an entity (candidates)

Entity-Relationship (ER) Diagrams

October 17, 2020 11


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Note: Delay Artificial Identifiers


• You will commonly see real database
schemas using internal, unique identifiers
– In Chinook: ArtistId, AlbumId, TrackId, …

• This is a reasonable design choice for many


tables/databases

• HOWEVER, we typically leave this to logical


design (since it can detract from ease of
communication during conceptual)

Entity-Relationship (ER) Diagrams

October 17, 2020 12


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Derived Attributes
Age

The value can be Make Year Model


computed

All cars have a year, Color CAR VIN

age, make, model,


registration (unique), Registration
vehicle number (vin;
unique), some number State Number
of colors.

Entity-Relationship (ER) Diagrams

October 17, 2020 13


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Note: Exercises
• As we learn notation, we’ll build up a
relatively large ERD

• It will start incorrect, but we’ll then revise

Entity-Relationship (ER) Diagrams

October 17, 2020 14


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Exercise
Draw an ERD for the following description:

Each department has a unique name, a


unique number, and a particular employee
who manages the department. We keep
track of the start date when that employee
began managing the department. A
department may have several locations.

Entity-Relationship (ER) Diagrams

October 17, 2020 15


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer

Name Number

Location DEPARTMENT Manager

Manager_
Start_Date

Entity-Relationship (ER) Diagrams

October 17, 2020 16


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Exercise
Draw an ERD for the following description:

A department controls a number of projects,


each of which has a unique name, a unique
number, and a single location.

Entity-Relationship (ER) Diagrams

October 17, 2020 17


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer

Name Number

Location PROJECT

Controlling_
Department

Entity-Relationship (ER) Diagrams

October 17, 2020 18


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Exercise
Draw an ERD for the following description:

We store each employee’s name (first, last, MI),


Social Security number (SSN), street address, salary,
sex (gender), and birth date. An employee is
assigned to one department, but may work on
several projects, which are not necessarily controlled
by the same department. We keep track of the
current number of hours per week that an employee
works on each project. We also keep track of the
direct supervisor of each employee (who is another
employee).
Entity-Relationship (ER) Diagrams

October 17, 2020 19


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer
Salary

SSN Sex

Department Birthdate

EMPLOYEE
Supervisor Address

FName Name Works_On Project

MI LName Hours

Entity-Relationship (ER) Diagrams

October 17, 2020 20


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Exercise
Draw an ERD for the following description:

We want to keep track of the dependents of


each employee for insurance purposes. We
keep each dependent’s first name, sex, birth
date, and relationship to the employee.

Entity-Relationship (ER) Diagrams

October 17, 2020 21


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer

Sex

Employee

DEPENDENT DBirthdate

Relationship

DName

Entity-Relationship (ER) Diagrams

October 17, 2020 22


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Relationships
Associates one or more sets of entities
– One = recursive (role is important)

STUDENT DEPT

CHAIR_F

All departments have a faculty


member who serves as the chair. A
faculty member can only chair one FACULTY
department.

Entity-Relationship (ER) Diagrams

October 17, 2020 23


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Relationships
Associates one or more sets of entities
– One = recursive (role is important)
MAJOR_D

STUDENT DEPT

CHAIR_F

All students must have a department


in which they major.
FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 24


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Relationships
Associates one or more sets of entities
– One = recursive (role is important)
MAJOR_D

STUDENT DEPT

MINOR_D

CHAIR_F

Students may have any number of


departments in which they minor.
FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 25


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Relationships
Associates one or more sets of entities
– One = recursive (role is important)
MAJOR_D

STUDENT DEPT

MINOR_D
Tutor Tutee

TUTORS CHAIR_F

Students can tutor other student(s).

FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 26


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Cardinality Ratios
Constrains the (maximum) number of entities that
can participate in each role of the relationship

MAJOR_D

STUDENT DEPT

MINOR_D
1
Tutor Tutee

TUTORS CHAIR_F

All departments have a faculty 1


member who serves as the chair. A
faculty member can only chair one FACULTY
department.

Entity-Relationship (ER) Diagrams

October 17, 2020 27


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Cardinality Ratios
Constrains the (maximum) number of entities that
can participate in each role of the relationship
N MAJOR_D 1
STUDENT DEPT

MINOR_D
1
Tutor Tutee

TUTORS CHAIR_F

All students must have a department 1


in which they major.
FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 28


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Cardinality Ratios
Constrains the (maximum) number of entities that
can participate in each role of the relationship
N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee

TUTORS CHAIR_F

Students may have any number of 1


departments in which they minor.
FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 29


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Cardinality Ratios
Constrains the (maximum) number of entities that
can participate in each role of the relationship
N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee
N M
TUTORS CHAIR_F

Students can tutor other student(s). 1

FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 30


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Multi-Valued Attributes vs Entity


• Both will have similar tabular structures

• Only entities can be uniquely identified,


and thus have relationships with other
entities

Entity-Relationship (ER) Diagrams

October 17, 2020 31


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Structural Constraints
If an entity does not exist unless it appears with an entity in a
relationship, the participation is total (existence dependency).
Else, partial. (Another view: minimum = {0, 1})

N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee
N M
TUTORS CHAIR_F

All departments have a faculty 1


member who serves as the chair. A
faculty member can only chair one FACULTY
department.

Entity-Relationship (ER) Diagrams

October 17, 2020 32


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Structural Constraints
If an entity does not exist unless it appears with an entity in a
relationship, the participation is total (existence dependency).
Else, partial. (Another view: minimum = {0, 1})

N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee
N M
TUTORS CHAIR_F

All students must have a department 1


in which they major.
FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 33


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Attributes of Relationships
1->1, can go to either entity
1->N, can go to (1) entity
N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee
N M
TUTORS Office CHAIR_F

1
Each department chair has an office.
FACULTY

Entity-Relationship (ER) Diagrams

October 17, 2020 34


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Attributes of Relationships
1->1, can go to either entity
1->N, can go to (1) entity
Done

N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee
N M
TUTORS Office CHAIR_F

1
It is important to know whether or
not a student has completed their FACULTY
major.

Entity-Relationship (ER) Diagrams

October 17, 2020 35


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Attributes of Relationships
1->1, can go to either entity
1->N, can go to (1) entity
Done

N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee
N M
TUTORS Done Office CHAIR_F

1
It is important to know whether or
not a student has completed each of FACULTY
their minor(s).

Entity-Relationship (ER) Diagrams

October 17, 2020 36


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Attributes of Relationships
1->1, can go to either entity
1->N, can go to (1) entity
Done

N MAJOR_D 1
STUDENT DEPT
N M
MINOR_D
1
Tutor Tutee
N M
TUTORS Done Office CHAIR_F

Subject
1
It is important to know the subject(s)
in which a tutee is being tutored by FACULTY
each tutor.

Entity-Relationship (ER) Diagrams

October 17, 2020 37


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Weak Entities
Entity types that do not have key attributes
of their own are weak; instead identified by
relation to specific entity of another type
(the identifying type)
Prof

1 COURSE N
COURSE SEC
SECTION

NAME Number Book

DEPT NUM

Entity-Relationship (ER) Diagrams

October 17, 2020 38


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Revise!
We store each employee’s
name (first, last, MI), Social
Security number (SSN), street
address, salary, sex (gender),
and birth date. An employee is Salary)

assigned to one department, SSN) Sex)

but may work on several


projects, which are not Department) Birthdate)

necessarily controlled by the EMPLOYEE)


same department. We keep Supervisor) Address)

track of the current number of


hours per week that an FName) Name) Works_On) Project)

employee works on each


project. We also keep track MI) LName) Hours)

of the direct supervisor of


each employee (who is
another employee).

Entity-Relationship (ER) Diagrams

October 17, 2020 39


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer
Salary

SSN Sex Department

1
Supervisor Birthdate
Supervision

EMPLOYEE
Address
Supervisee
N
FName Name Works_On Project

MI LName Hours

Entity-Relationship (ER) Diagrams

October 17, 2020 40


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Revise!
Salary)

We want to keep track 1)


SSN) Sex) Department)

of the dependents of Supervisor)

Supervision)
Birthdate)

EMPLOYEE)

each employee for N)


Supervisee)
Address)

insurance purposes. We FName) Name) Works_On) Project)

keep each dependent’s MI) LName) Hours)

first name, sex, birth


date, and relationship to Sex(

the employee.
Employee(

DEPENDENT( DBirthdate(

Rela7onship(

DName(

Entity-Relationship (ER) Diagrams

October 17, 2020 41


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer
Salary

SSN Sex Department

1
Supervisor
Birthdate
Supervision

EMPLOYEE
Address
Supervisee
1
N

FName Name Works_On Project

Sex
MI LName Hours

DEPENDENT N
DEPENDENT DBirthdate
_OF

Relationship

DName

Entity-Relationship (ER) Diagrams

October 17, 2020 42


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Revise!
A department controls Name' Number'

a number of projects, Loca%on' PROJECT'


each of which has a
unique name, a unique Controlling_'
Department'

number, and a single


location. Name' Number'

Loca%on' DEPARTMENT' Manager'

Manager_'
Start_Date'

Entity-Relationship (ER) Diagrams

October 17, 2020 43


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer
Name Number

Location PROJECT

Name Number
N

1
CONTROLS DEPARTMENT Manager

Manager_
Location
Start_Date

Entity-Relationship (ER) Diagrams

October 17, 2020 44


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Revise!
Name' Number'

Each department has a …


particular employee who Loca%on' PROJECT'

manages the department. N' Name' Number'

1'
CONTROLS' DEPARTMENT' Manager'

An employee is assigned
to one department, but Loca%on'
Manager_'

may work on several


Start_Date'

projects, which are not Salary)

necessarily controlled by
SSN) Sex) Department)

1)
Supervisor)

the same department. We


Birthdate)

Supervision)
EMPLOYEE)
Address)
Supervisee)

keep track of the current


1)
N)

FName) Name) Works_On) Project)

number of hours per MI) LName) Hours)


Sex)

week that an employee DEPENDENT N)


DEPENDENT) DBirthdate)

works on each project.


_OF)

RelaIonship)

DName)

Entity-Relationship (ER) Diagrams

October 17, 2020 45


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer
Supervisor Supervisee
1 N
Hours Supervision

M
WORKS_ON EMPLOYEE SSN

1 N
Name

Start
_Date
N

Location PROJECT Manages

Number
1

1 1
CONTROLS DEPARTMENT Works_For

Name Number
Location

Entity-Relationship (ER) Diagrams

October 17, 2020 46


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

All Together Now!

Entity-Relationship (ER) Diagrams

October 17, 2020 47


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Specialization/Generalization
Only a subset of entities within a type have
certain attributes or participate in certain
relationships
ID

STUDENT

GRAD_STUDENT Degrees

Entity-Relationship (ER) Diagrams

October 17, 2020 48


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Multiple Subtypes: Disjointedness


(o)verlap: may be more than one
(d)isjoint: entities may only be one subtype
SSN

A person can be an
employee, an
PERSON
alumnus, and/or a
student
o

U
U

U
EMPLOYEE ALUMNUS STUDENT

Entity-Relationship (ER) Diagrams

October 17, 2020 49


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Multiple Subtypes: Disjointedness


(o)verlap: may be more than one
(d)isjoint: entities may only be one subtype
SSN

A person can be
either an employee,
PERSON
an alumnus, or a
student
d

U
U

U
EMPLOYEE ALUMNUS STUDENT

Entity-Relationship (ER) Diagrams

October 17, 2020 50


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Multiple Subtypes: Completeness


Similar to relationships; can be total (must
belong to subtypes) or partial (can belong)
SSN

A person must be
exactly one: an
PERSON
employee, an
alumnus, or a student
d

U
U

U
EMPLOYEE ALUMNUS STUDENT

Entity-Relationship (ER) Diagrams

October 17, 2020 51


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Exercise
• The database keeps track of three types of persons: employees, alumni, and students. A
person can belong to one, two, or all three of these types. Each person has a name, SSN,
sex, address, and birth date.

• Every employee has a salary, and there are three types of employees: faculty, staff, and
student assistants. Each employee belongs to exactly one of these types. For each
alumnus, a record of the degree or degrees that they earned at the university is kept,
including the name of the degree, the year granted, and the major department. Each
student has a major department.

• Each faculty has a rank, whereas each staff member has a staff position. Student
assistants are classified further as either research assistants or teaching assistants, and
the percent of time that they work is recorded in the database. Research assistants have
their research project stored, whereas teaching assistants have the current course they
work on.

• Students are further classified as either graduate or undergraduate, with the specific
attributes degree program (M.S., Ph.D., M.B.A., and so on) for graduate students and
class (freshman, sophomore, and so on) for undergraduates.

Entity-Relationship (ER) Diagrams

October 17, 2020 52


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Answer

Entity-Relationship (ER) Diagrams

October 17, 2020 53


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Alternative Notation (1)


Figure A. 1

Entity-Relationship (ER) Diagrams

October 17, 2020 54


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Alternative Notation (2)


Figure A. 1

Entity-Relationship (ER) Diagrams

October 17, 2020 55


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Requirements Elicitation
The conceptual model should inform requirements elicitation questions:

• What are the main kinds of objects to be stored in the database


(entity types)?

• For each object, what information should be stored (attributes,


relationships)? What information distinguishes one object of a type
from another (keys, weak entities)? Are there different
kinds/categories of objects (specialization/generalization)?

• For each piece of information, what characterizes a valid value


(composite/multi-valued, structural, etc.)?

• For related objects x and y, can x exist without y (participation)?


How many x’s can a y have, and vice-versa (cardinality)?

Entity-Relationship (ER) Diagrams

October 17, 2020 56


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Approaches to Conceptual Design


Centralized
– Single authority responsible for merging
requirements into schema
– Reasonable for smaller applications

View Integration
– Each stakeholder implements local view
– Individual views integrated into global schema
– Individual views can be reconstructed as external
schemas after integration
Entity-Relationship (ER) Diagrams

October 17, 2020 57


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

View Integration (1)


1. Identify correspondences and conflicts
– Conflicts: names, types, domain, constraints
2. Modify views to conform
3. Merge
4. Restructure

Entity-Relationship (ER) Diagrams

October 17, 2020 58


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

View Integration (2)

Entity-Relationship (ER) Diagrams

October 17, 2020 59


CS3200 – Database Design・ ・ ・ Fall 2020・ ・ ・ Derbinsky

Summary
• The goal of conceptual design is to develop a set
of data requirements that are comprehensive,
clear & easy to understand, and algorithmically
transformable

• ER Diagrams (ERDs) are one such design model


that visually represent the entities, attributes,
and relationships of a system

• Requirements elicitation and conceptual design is


an iterative process that is a necessary
prerequisite to implementing a database

Entity-Relationship (ER) Diagrams

October 17, 2020 60

You might also like