Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments...

18
Data Modeling and Entity-Relationship Model II

Transcript of Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments...

Page 1: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

Data Modeling and Entity-Relationship Model II

Page 2: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 2

I want a database to maintain departments in my company. Store

information about my employees, their projects and assignments. I want ….

$$$

User requirement

A database

YOUR JOB!

Data Modeling (Ch.4)

Database Design (Ch.5)

Page 3: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 3

Overview of Chapter 4: Data Modeling

• Input: User requirement; Output: E-R Diagram• Use Entity-Relationship Diagram (E-R Diagram) to capture all user

requirements

Page 4: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 4

Review of Previous Class: Draw an Entity

Entity Name

Attributes

Identifier

Page 5: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 5

Review of Previous Class: Maximum Cardinality

• Relationships are named and classified by their cardinality, which is a word that means count

• maximum cardinality is the maximum number of entity instances that may participate in a relationship instance — one, many or other some fixed number– BASKETBALL-TEAM and PLAYER could be 1:5

Page 6: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 6

Review of Previous Class: Crow’s Foot Notation

USER VIDEO

USER CHANNEL

EMPLOYEE LOCKER

One Many (crow’s foot)

Attention: do not misplace one and many notations

An employee has (at most) one locker; a locker can belong to (at most) one employee

A user can upload many videos; a video can be uploaded by (at most) one user

A user can subscribe to many channels; a channel can be subscribed by many users

upload

subscribe

Page 7: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 7

How to Determine Maximum Cardinality?

USER VIDEO

USER CHANNEL

EMPLOYEE LOCKER

Attention: do not misplace one and many notations

An employee has (at most) one locker; a locker can belong to (at most) one employee

A user can upload many videos; a video can be uploaded by (at most) one user

A user can subscribe to many channels; a channel can be subscribed by many users

upload

subscribe

• User requirements• Common Sense

Page 8: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

Review Exercise

• Use crow’s foot notation to draw maximum cardinality on the following relationships:

SALESPERSON ORDER

PRODUCT ORDER

EMPLOYEE DEPARTMENT(is manager of)

Page 9: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 9

This Class

• Entity-Relationship Model– Entity, attribute, identifier, relationship– Maximum Cardinality: 1:1, 1:N, N:M– Minimum Cardinality: Optional, Mandatory

• Case Studies

Page 10: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 10

Minimum Cardinality

• Minimum cardinality is the minimum number of entity instances that must participate in a relationship instance– typically assumes a value of zero (optional) or one

(mandatory)

Mandatory Optional

Crow’s foot notation

Page 11: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 11

Minimum Cardinality

EMPLOYEE LOCKERAn employee may have a locker; a locker must belong to an employee

Mandatory Optional

Maximum cardinality notation is closer to entity

Minimum cardinality notation is closer to the middle

Page 12: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 12

Minimum Cardinality: Exercise

USER VIDEO

Mandatory Optional

What does the Minimum cardinality mean?(A) A user must upload a video; a video may belong to a user(B) A user may upload a video; a video must belong to a user(C) A user may upload a video; a video may belong to a user(D) A user must upload a video; a video must belong to a user

Page 13: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 13

Minimum Cardinality: Exercise

Which design is most suitable?• User requirements• Common sense

(A)

(B)

(C)

(D)

USER CHANNEL

subscribe

USER CHANNEL

USER CHANNEL

USER CHANNEL

Page 14: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 14

In-Class Exercise: Minimum Cardinality

In-Class Exercise A-3• Add Minimum Cardinality symbols on the line of the

relationship

In-Class Exercise B-3• Add Minimum Cardinality symbols on the line of the

relationship

Page 15: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 15

Multiple Relationships between Entities

StudentID ClubIDName

Email

STUDENT CLUB

ClubName

Description

president

member

• Sometimes, there could multiple relationships with different semantic meanings between two entities. • A club will have exactly one student as the president.

Students can also become members of the club.

Page 16: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 16

Multiple Relationships between Entities

UserID ProductIDName

Email

USER PRODUCT

Name

Description

Sell

Buy

A product must be sold by exactly one user. A product may or may not have a buyer yet.

Page 17: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 17

Summary

E-R Diagram: Entity-Relationship Diagram(1) entity; (2) identifier; (3) attributes; (4) relationship

UserID Video IDName

Address

Email

USER VIDEO

Title

Description

Length

A complete E-R Diagram represented using Crow’s Foot notation:

USER –> VIDEO: A user may upload zero to many videosVIDEO–> USER: A video must belong to exactly one user

Page 18: Data Modeling and Entity- Relationship Model II. IST2102 I want a database to maintain departments in my company. Store information about my employees,

IST210 18

An online E-R diagram drawing tool: www.draw.io