57
CS5200 – Database Management SystemsFall 2017Derbinsky Entity-Relationship (ER) Diagrams Lecture 8 October 12, 2017 Entity-Relationship (ER) Diagrams 1

Entity-Relationship (ER) Diagrams - Northeastern … –Database Management Systems・・・Fall 2017・・・Derbinsky Cardinality Ratios Constrains the number of entities that can

Embed Size (px)

Citation preview

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Entity-Relationship (ER) Diagrams

Lecture 8

October 12, 2017

Entity-Relationship (ER) Diagrams

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Outline1. Context– Design & Implementation Process

2. Goals of Conceptual Design3. Entity-Relationship (ER) Model4. One ER Diagrammatic Notation5. Requirements Elicitation6. Approaches to Conceptual Design

October 12, 2017

Entity-Relationship (ER) Diagrams

2

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Database Design and Implementation Process

October 12, 2017

Entity-Relationship (ER) Diagrams

3

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Goal of Conceptual DesignDescription 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

October 12, 2017

Entity-Relationship (ER) Diagrams

4

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Entity-Relationship (ER) ModelEntity• 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)

October 12, 2017

Entity-Relationship (ER) Diagrams

5

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

ER Diagrams• Graphical depiction

of an ER model• Many notations, this

class…

Specialization/Generalization

October 12, 2017

Entity-Relationship (ER) Diagrams

6

Allcarshaveayear,age,make,model,registration(unique),vehiclenumber(vin;unique),somenumberofcolors…

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Entity SetsSet of entities that have the same attributes

All cars have a year, make, and model.

October 12, 2017

Entity-Relationship (ER) Diagrams

7

CAR

Year ModelMake

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Composite AttributesCan be subdivided into smaller subparts

All cars have a year, make, model, and registration.

October 12, 2017

Entity-Relationship (ER) Diagrams

8

CAR

Year ModelMake

Registration

NumberState

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Multivalued AttributesCan take a [possibly specified] number of values.

All cars have a year, make, model, registration, and some number of colors.

October 12, 2017

Entity-Relationship (ER) Diagrams

9

CAR

Year ModelMake

Registration

NumberState

Color

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Key AttributesThe value uniquely identifies each entity

All cars have a year, make, model, registration (unique), vehicle number (vin; unique), some number of colors.

October 12, 2017

Entity-Relationship (ER) Diagrams

10

CAR

Year ModelMake

Registration

NumberState

VINColor CAR

Year ModelMake

Registration

NumberState

VINColor

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Potential Pitfall• In relational schema, underlining multiple

attributes indicates that for all rows, the combination is unique

• In ERDs, underlining multiple attributes indicates that each individually can uniquely identify an entity

October 12, 2017

Entity-Relationship (ER) Diagrams

11

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Derived AttributesThe value can be computed

All cars have a year, age, make, model, registration (unique), vehicle number (vin; unique), some number of colors.

October 12, 2017

Entity-Relationship (ER) Diagrams

12

Color CAR

Year ModelMake

Registration

NumberState

VIN

Age

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

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

October 12, 2017

Entity-Relationship (ER) Diagrams

13

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

14

Location DEPARTMENT Manager

NumberName

Manager_Start_Date

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

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

October 12, 2017

Entity-Relationship (ER) Diagrams

15

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

16

Location PROJECT

NumberName

Controlling_Department

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

ExerciseDraw 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).

October 12, 2017

Entity-Relationship (ER) Diagrams

17

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

18

Department

EMPLOYEE

SexSSN

Name

Salary

Supervisor

Birthdate

Address

Works_OnFName

LNameMI Hours

Project

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

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

October 12, 2017

Entity-Relationship (ER) Diagrams

19

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

20

Employee

DEPENDENT

Sex

DName

DBirthdate

Relationship

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

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

October 12, 2017

Entity-Relationship (ER) Diagrams

21

DEPTSTUDENT

FACULTY

CHAIR_F

Alldepartmentshaveafacultymemberwhoservesasthechair.Afacultymembercanonlychaironedepartment.

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

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

October 12, 2017

Entity-Relationship (ER) Diagrams

22

DEPTSTUDENT

FACULTY

CHAIR_F

Allstudentsmusthaveadepartmentinwhichtheymajor.

MAJOR_D

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

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

October 12, 2017

Entity-Relationship (ER) Diagrams

23

DEPTSTUDENT

FACULTY

CHAIR_F

Studentsmayhaveanynumberofdepartmentsinwhichtheyminor.

MAJOR_D

MINOR_D

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

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

October 12, 2017

Entity-Relationship (ER) Diagrams

24

DEPTSTUDENT

FACULTY

CHAIR_F

Studentscantutorotherstudent(s).

MAJOR_D

MINOR_D

TUTORS

TuteeTutor

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Cardinality RatiosConstrains the number of entities that can participate in each role of the relationship

October 12, 2017

Entity-Relationship (ER) Diagrams

25

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee

Alldepartmentshaveafacultymemberwhoservesasthechair.Afacultymembercanonlychaironedepartment.

1

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Cardinality RatiosConstrains the number of entities that can participate in each role of the relationship

October 12, 2017

Entity-Relationship (ER) Diagrams

26

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee 1

1Allstudentsmusthaveadepartmentinwhichtheymajor.

1N

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Cardinality RatiosConstrains the number of entities that can participate in each role of the relationship

October 12, 2017

Entity-Relationship (ER) Diagrams

27

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee 1

1Studentsmayhaveanynumberofdepartmentsinwhichtheyminor.

MN

N 1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Cardinality RatiosConstrains the number of entities that can participate in each role of the relationship

October 12, 2017

Entity-Relationship (ER) Diagrams

28

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee 1

1

MN

Studentscantutorotherstudent(s).

MN

N 1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Structural ConstraintsIf an entity does not exist unless it appears with an entity in a relationship, the participation is total (existence dependency). Else, partial.

October 12, 2017

Entity-Relationship (ER) Diagrams

29

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee 1

1

MN

MN

Alldepartmentshaveafacultymemberwhoservesasthechair.Afacultymembercanonlychaironedepartment.

N 1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Structural ConstraintsIf an entity does not exist unless it appears with an entity in a relationship, the participation is total (existence dependency). Else, partial.

October 12, 2017

Entity-Relationship (ER) Diagrams

30

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee

1

MN

MN

N

Allstudentsmusthaveadepartmentinwhichtheymajor.

1

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Attributes of Relationships1->1, can go to either entity1->N, can go to (1) entity

October 12, 2017

Entity-Relationship (ER) Diagrams

31

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee

1

MN

MN

Office

Eachdepartmentchairhasanoffice.

1N

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Attributes of Relationships1->1, can go to either entity1->N, can go to (1) entity

October 12, 2017

Entity-Relationship (ER) Diagrams

32

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee

1

MN

MN

Office

Itisimportanttoknowwhetherornotastudenthascompletedhis/hermajor.

Done

1N

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Attributes of Relationships1->1, can go to either entity1->N, can go to (1) entity

October 12, 2017

Entity-Relationship (ER) Diagrams

33

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee

1

MN

MN

Office

Itisimportanttoknowwhetherornotastudenthascompletedeachofhis/herminor(s).

Done

Done

1N

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Attributes of Relationships1->1, can go to either entity1->N, can go to (1) entity

October 12, 2017

Entity-Relationship (ER) Diagrams

34

DEPTSTUDENT

MINOR_D

FACULTY

TUTORS CHAIR_F

MAJOR_D

Tutor Tutee

1

MN

MN

Office

Itisimportanttoknowthesubject(s)inwhichatuteeisbeingtutoredbyeachtutor.

Done

Done

Subject

1N

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Weak EntitiesEntity 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)

October 12, 2017

Entity-Relationship (ER) Diagrams

35

SECTIONCOURSE COURSESEC

Number

SECTION

BookNAME

DEPT NUM

Prof

1 N

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ 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 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).

October 12, 2017

Entity-Relationship (ER) Diagrams

36

Department)

EMPLOYEE)

Sex)SSN)

Name)

Salary)

Supervisor)

Birthdate)

Address)

Works_On)FName)

LName)MI) Hours)

Project)

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

37

Department

EMPLOYEE

SexSSN

Name

Salary

Birthdate

Address

Works_OnFName

LNameMI Hours

Project

Supe

rvision

Supervisor

Supervisee

1

N

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Revise!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.

October 12, 2017

Entity-Relationship (ER) Diagrams

38

Employee(

DEPENDENT(

Sex(

DName(

DBirthdate(

Rela7onship(

Department)

EMPLOYEE)

Sex)SSN)

Name)

Salary)

Birthdate)

Address)

Works_On)FName)

LName)MI) Hours)

Project)

Supe

rvision

) Supervisor)

Supervisee)

1)

N)

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

39

Department

EMPLOYEE

SexSSN

Name

Salary

Birthdate

Address

Works_OnFName

LNameMI Hours

Project

Supe

rvision

Supervisor

Supervisee

1

N

DEPENDENT

Sex

DName

DBirthdate

Relationship

DEPENDENT_OF

N

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Revise!A department controlsa number of projects, each of which has a unique name, a unique number, and a single location.

October 12, 2017

Entity-Relationship (ER) Diagrams

40

Loca%on' PROJECT'

Number'Name'

Controlling_'Department'

Loca%on' DEPARTMENT' Manager'

Number'Name'

Manager_'Start_Date'

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

41

Location PROJECT

NumberName

Location

DEPARTMENT Manager

NumberName

Manager_Start_Date

CONTROLS1

N

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Revise!Each department has a … particular employee who manages the department.

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.

October 12, 2017

Entity-Relationship (ER) Diagrams

42

Loca%on' PROJECT'

Number'Name'

Loca%on'

DEPARTMENT' Manager'

Number'Name'

Manager_'Start_Date'

CONTROLS'1'

N'

Department)

EMPLOYEE)

Sex)SSN)

Name)

Salary)

Birthdate)

Address)

Works_On)FName)

LName)MI) Hours)

Project)Supe

rvision

) Supervisor)

Supervisee)

1)

N)

DEPENDENT)

Sex)

DName)

DBirthdate)

RelaIonship)

DEPENDENT_OF)

N)

1)

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

43

Location PROJECT

Number

Name

Location

DEPARTMENT

NumberName

CONTROLS1

N

EMPLOYEE SSNWORKS_ON

N

M

Hours SupervisionN1

Supervisor Supervisee

Manages

1

1

Start_Date

Works_For

N

1

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

All Together Now!

October 12, 2017

Entity-Relationship (ER) Diagrams

44

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Specialization/GeneralizationOnly a subset of entities within a type have certain attributes or participate in certain relationships

October 12, 2017

Entity-Relationship (ER) Diagrams

45

STUDENT

ID

GRAD_STUDENT Degrees

U

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Multiple Subtypes: Disjointedness(o)verlap: may be more than one(d)isjoint: entities may only be one subtype

October 12, 2017

Entity-Relationship (ER) Diagrams

46

PERSON

SSN

EMPLOYEE ALUMNUS STUDENT

Uo

Apersoncanbeanemployee,an

alumnus,and/orastudent

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Multiple Subtypes: Disjointedness(o)verlap: may be more than one(d)isjoint: entities may only be one subtype

October 12, 2017

Entity-Relationship (ER) Diagrams

47

PERSON

SSN

EMPLOYEE ALUMNUS STUDENT

U

Apersoncanbeeither anemployee,analumnus,ora

studentd

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Multiple Subtypes: CompletenessSimilar to relationships; can be total (mustbelong to subtypes) or partial (can belong)

October 12, 2017

Entity-Relationship (ER) Diagrams

48

PERSON

SSN

EMPLOYEE ALUMNUS STUDENT

U

Apersonmust beexactlyone:anemployee,an

alumnus,orastudentd

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ 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 he or she 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 under- graduates.

October 12, 2017

Entity-Relationship (ER) Diagrams

49

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Answer

October 12, 2017

Entity-Relationship (ER) Diagrams

50

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Alternative Notation (1)Figure A. 1

October 12, 2017

Entity-Relationship (ER) Diagrams

51

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Alternative Notation (2)Figure A. 1

October 12, 2017

Entity-Relationship (ER) Diagrams

52

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Requirements ElicitationThe 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)?

October 12, 2017

Entity-Relationship (ER) Diagrams

53

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

Approaches to Conceptual DesignCentralized– 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 integrationOctober 12, 2017

Entity-Relationship (ER) Diagrams

54

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

View Integration (1)1. Identify correspondences and conflicts– Conflicts: names, types, domain, constraints

2. Modify views to conform3. Merge4. Restructure

October 12, 2017

Entity-Relationship (ER) Diagrams

55

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ Derbinsky

View Integration (2)

October 12, 2017

Entity-Relationship (ER) Diagrams

56

CS5200 – Database Management Systems・ ・・ Fall 2017・ ・・ 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

October 12, 2017

Entity-Relationship (ER) Diagrams

57