conceptual modeling with er diagrams peter chen introduced er diagrams

35
Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Upload: paul-walton

Post on 26-Dec-2015

224 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Conceptual Modelingwith ER Diagrams

Peter Chen

introduced ER Diagrams

Page 2: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

E-R Modeling

E-R Modeling is a design methodology for modeling the – Entities– Relationships

using a diagram with specified shapes for entities, relationships, roles of entities in these relationships, and cardinality.

Page 3: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

E-R Diagram Conventions

Symbol Meaning

Entity Type

Weak Entity Type

Relationship

Identifying Relationship

Attribute

Page 4: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

ER-Diagram Conventions - CONTINUED

Symbol Meaning

Key Attribute

Multivalued Attribute

Composite Attribute

Page 5: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Entities, Relationships and Attributes

Employee

• A entity is a object or event which needs to be tracked. Attributes characterize entity sets and relationships. Relationships relate two entity sets

Employee ProjectAssigned

Name Date

SSNum

Name

Page 6: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Payroll Application

A contractor does custom work (projects). He keeps track of employee time for each project. Besides materials, the customer is charged by invoice for employee time on his job. To keep track of employee time, the employee submits a time sheet with entries of project number, hours, description. These are entered into the system along with the employee ID. The hourly rate for the employee is used for each entry to generate a labor charge. The labor charges are totaled for each project and used as a basis for the customer invoice.

Page 7: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Understanding the Requirements

Management

EndUsers

Analysts

Conference

• Management – know high level business rules

• End users – have used paper system or previous software system and have expectations

• Analysts – have understanding of what can / cannot be done and must requirements into system

Page 8: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

ER Diagrams for Payroll

Step 1. Identify the Entity Sets with Attributes

• Customers : Name, Address,Phone,CustID• Projects : Name,Description,ProjID,Total,CustID• Employees : Name,SSNo,PayRate,EmpID• LaborCharges : EmpID,ProjID,Description,Hours,Amount

Page 9: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

ER Diagrams for Payroll

Step 1. Identify Relationships between Entity Sets with any Attributes

• Customers Has Project … Project is Weak Entity Set• Employee Works_On Project• Employee Has_Labor_Charge For Project … Labor_Charge is Weak Entity Set

Page 10: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

E-R Modeling – Entity Sets, Attributes, Relationships

Racquet Club Example

• A Racquet Club has members with one year or two year contracts.

• Members pay contract amount up front, quarterly, or monthly.

• Members may reserve a court for the next day.

Page 11: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

E-R Modeling – Entity Sets, Attributes, RelationshipsRacquet Club Example Continued

• Entity Sets

– Members : Name, Start, Contract_Amount, Contract_Period, Initial_Balance, Member_ID

– Payments : PayerID, Amount, Paid_Date, Payment_ID

– Reservations : Member_ID, CourtNumber, Hour• Relations :

– Member - Makes – Payment– Member - Makes - Reservation

Page 12: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Data Modeling –

Racquet Club Example

Page 13: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Keys, Cardinality Constraints and Participation Constraints

• A key of a relation is a minimal set of attributes and roles which uniquely determine each entity.

• A cardinality constraint m..n constrains the number of times a single entity can participate in a role of a relationship : m <= times <= n.

• A participation constraint ensures that an entity will particpate at least this many times.

Page 14: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

ER-Diagram Cardinality Conventions Symbol Meaning

Calculated Attribute

Cardinality Constraints and Participation Constraints

0 .. *

0 .. 1

1 .. *

1 .. 1

Page 15: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Cardinality and Participationin the E-R model.

1 .. 2 means that at least 1 d must participate in the A relation with C and that not more that 2 d’s can participate. If A is represented by a table, then there is at least one row and not more than 2 rows with a single c value.

Page 16: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Many-to-one, one-to-one, and many-to-many correspondences

Page 17: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Cardinality & Participation Constraints

Library Circulation

Motel/Hotel

Video Store

Employment Company

Page 18: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Cardinality & Participation Constraints

Library Circulation

Book is_checked_out to Patron

Motel/Hotel Customer rents a room

Video Store Customer rents a video

Employment Company

Applicant is hired for a job

Page 19: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Example of an E-R diagram with an ISA hierarchy.

Page 20: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Using IsA for data partitioning.

New York Customer Pennsylvania Customer

Page 21: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Participation Constraints

A participation constraint is a lower bound on the number of times an entity can particpate in a relation.

Examples:

An employee belongs to ONE department. This is a participation and a cardinality constraint 1 .. 1.

Employee Department

0 .. *

0 .. 1

1 .. *

1 .. 1

Page 22: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Participation constraints.

Page 23: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Relationship Types – Two Entity Set Relations

A customer will pay for

at least one project

ProjectAssignedTo

Employee

Num-Hours

ProjectWill PayFor

Fixed-Cost

Customer

An employee is assigned to at least one project (participation)

Page 24: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Relationship Types – One & Three Entity Set Relations

One Set : ReportsTo( SupID, SubID )

Three Sets :

Sale( ProdID, CustID,SuppID;Date)

Employee Reports_To

subordinate

supervisor

Customer Product

Supplier

Sold

Date Price

Page 25: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

ER Diagrams for Payroll

Customer

Name

Address

Phone

CustID

Projects

Name

Description

Total

CustID

ProjID

Has

Page 26: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

ER Diagrams for Payroll

Employee

Name

SSNo

PayRate

EmpID

TimeSheet

Year

Month

EmpID

TSID

Has

PayCheck

Has

Labor Charges

Has

TSID

. . .

NetPay

TSID

. . .

Amount

Page 27: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

The IS-A Relationship

Employee

Is-A

SalariedEmployee

Hourly Employee

disjoint

Name SSNo

SalaryPayRate

Page 28: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Construct an ER Diagram

• Lawn Furniture Manufacturer

• Stores Information for Catalog of products and parts

• Stores Information for Manufacturing, including quantity on hand

• Identify product entities (picnic table and lawn chair) with attributes

• Identify relationships IsA and PartOf

Page 29: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

The Part-Of Relationship

Picnic_Table Lawn_Chair

ProdNo ProdNo

Part_Of

OutDoorProducts

IsA

Top Base Seats

QuantityProdNo

Price Price

Price

Page 30: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

From E-R Diagrams toRelational Database Schema

• Converting entities into relations (tables)– Each entity becomes a relation– Each attribute of the entity becomes an

attribute of that relation (column)

– If attributes K1 ... Kn form a key of the entity, then K1 ... Kn form a candidate key of the relation.

Page 31: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

From ER Diagramsto Relational Database Schema

• Translating Entities

EmployeeName SSNo

TypeHireDate

Termination

Create Table Employee ( Name char(20), Type char(1), HireDate date,

Termination date, SSNo char(9),

Primary Key (SSNo) )

Page 32: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

From E-R Diagrams toRelational Database Schema

• Representing relationships in the database schema– R is a relationship between entity set A and weak

entity set B• A becomes a relation with primary key K and B+K becomes

a relation with K being a foreign key – e.g. employees and dependents

– R is a relationship between entity sets A,B and C• A,B and C become relations with KA , KB , and Kc as keys. R

becomes a relation with foreign keys KA , KB , and Kc

Page 33: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

From ER Diagramsto Relational Database Schema

• Translating Relationships

Customer Product

Supplier

Sold

SaleDate Price

Create Table Sold ( SaleDate Date, Price Currency, SaleID autonumber,

Customer Integer, Supplier Integer, Product Integer,

Primary Key (SaleID),

Foreign Key ( Customer ) References Customers( CustID),

Foreign Key ( Supplier ) References Suppliers( SuppID ),

Foreign Key ( Product ) References Products ProdID ) )

SaleID

Page 34: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Translate into Schema

Employee

Is-A

SalariedEmployee

Hourly Employee

disjoint

Name SSNo

SalaryPayRate

Page 35: Conceptual Modeling with ER Diagrams Peter Chen introduced ER Diagrams

Translate Into Schema

Picnic_Table Lawn_Chair

ProdNo ProdNo

Part_Of

OutDoorProducts

IsA

Top Base Seats

QuantityProdNo

Price Price

Price