data modeling with erd bus 782. database examples sales database: –customer table –orders table...

28
Data Modeling with ERD BUS 782

Upload: holly-mccormick

Post on 11-Jan-2016

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Data Modeling with ERD

BUS 782

Page 2: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Database Examples• Sales database:

– Customer table– Orders table– LineItem table– Products table

• University database:– Student table– Account table– Faculty table– Course table– Registration table

Page 3: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Entities

• An entity is a person, place, object, event, or concept in the user environment about which the organization wishes to maintain data.– Person: Employee, Student, patient– Place: Warehouse, Store– Object: Product, Machine.– Event: Registration, Sale, Renewal– Concept: Account, Course

• Physical existence:• Customer, student, product, etc.

• Conceptual existence:• Bank accounts

Page 4: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Entity Type

• A collection of entities that share common properties or characteristics.

• An entity type represents a collection of entities.

• A business environment may involve many entity types.– University: Faculty, Student, Course– Department, Employee, Dependent– Sales person, Customer, Order

Page 5: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Relationship

• Relationship: Interaction between entity types.– Faculty teach Course, Faculty advise Student– Customer open Account, Customer purchase

Product.

• Binary relationship: A relationship involves two entity types.

• Three types of binary relationship:– 1:1, 1:M, M:M

Page 6: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Entity-Relationship Diagram

• ER modeling begins by identifying the entities and relationships between entities that must be represented in the model.

• In an ERD, an entity type is represented by a rectangle labeled with a singular name.

• A relationship has a verb phrase name:– Faculty teach Course, Faculty advise Student

Page 7: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

M:M Relationship

Peter

Paul

John

Woody

Alan

Mary

Linda

Nancy

Mia

Pia

A boy may date 0, 1, or many girls.

A girl may date 0, 1, or many boys.

Note: “Many boys date many girls” is not a correct interpretation.

Boy Girl

Page 8: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

1:1 Relationship

Peter

Paul

John

Woody

Alan

Mary

Linda

Nancy

Mia

Pia

A man may marry 0 or 1 woman.

A woman may marry 0 or 1 man.

Man Woman

Page 9: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

1:M Relationship

Peter

Paul

John

Woody

Alan

MaryBrianLindaAron

NancyRonald

MiaPia

A father has 1 or many children.

A child has 1 father.

Father Child

Page 10: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Other Examples• 1:1

– State, State Governor– Order, Invoice

• 1:M– Department, Employee– Customer, Order

• M:M– Bank customer, Bank account– Student, Student organization

Page 11: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

ERD Notations

Student Account

Faculty Course

Has1 1

EnrollM MAdvise

M

1

TeachM1

Page 12: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Alternative Notations

Student Account

Faculty Course

Has

Teach

Enroll

Advise

Page 13: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Attributes• Properties of an entity or a relationship.

• Simple attributes vs Composite attributes– Address:Street address, City, State,

ZipCode

• Single-valued attributes vs multivalued attributes

• Derived attributes

• Primary key

Page 14: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Student

SIDFname

LnameDateOfBirth

Age

FullName

Major

Page 15: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Domains of Attributes

• The set of allowable values for one or more attributes.

• Input validation

• Examples:– Sex: F, M– EmpHourlyWage: Between 6 and 300– EmpName: 50 charcters

Page 16: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Introduction to Relational Database

• Data is logically structured within relations.

• Each relation is a table (file) with named columns (attributes, fields) and rows (records).

Page 17: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Properties of a Relation

• Simple attribute– No composite, no multivalued attribute

• Each relation must have a primary key:– Simple or composite key– May have other keys (candidate keys)– Key cannot be null– Cannot be duplicated

Page 18: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Relational Database Design

• Create a table for each entity type that includes all simple attributes

• Relationship: – 1:1, 1:M

• Relationship table• Foreign key

– M:M: relationship table

Page 19: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Database Design Example

• University:– 1:1 Relationship:

• Student and Account– What is Peter’s account balance– Find students that owe more than 2000 dollars.

– 1:M Relationship• Faculty Advisor and student

– Who is Peter’s advisor?– How many students advised by Chao?

– M:M Relationship• Student and course

– How many units Peter takes?– Find students that are taking 363.

Page 20: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Database Design Example

• Bank:– Customer, Account, bank employee

Page 21: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Database Design Example

• Order Processing:– Customer, Order, Product

Page 22: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Advanced Topics

• Composite key• Multivalued attribute

– Student’s Major attribute– Faculty’s DegreeEarned attribute– Vehicle’s Color attribute– Others: PhoneNumber, EmailAddress

• Create a table for each multi-valued attribute• Key + attribute

• Attributes on a relation

Page 23: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Online Shopping Cart

Customer ShoppingCart

Product

Has

Has

1 M

M

M

CID Cname Addr CartID Date

PIDPname

Price

Phone

Page 24: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Order Form

Page 25: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Online Shopping Cart

Customer ShoppingCart

Product

Has

Has

1 M

M

M

CID Cname Addr CartID Date

Qty

PIDPname

Price

Phone

Page 26: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Attributes on Relationship

• Examples:– Student/Course: Grade– Order/Product: Quantity

Page 27: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Attorney CaseMM

CourtJudge

AID

AnamePhone CID Cname

JID Jname

M

1

1M

CtID Address

Hours

Email

Page 28: Data Modeling with ERD BUS 782. Database Examples Sales database: –Customer table –Orders table –LineItem table –Products table University database: –Student

Suggested Readings

• http://www.youtube.com/watch?v=u2QqjofJvGo• http://en.wikipedia.org/wiki/Entity-relationship_model

• http://dhdurso.org/articles/database-design.html