Top Banner
Entity Relationship Diagrams
36

Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Entity Relationship Diagrams

Page 2: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Supplier

Shipment Item ProductionPlan

ProductMaster

Schedule

Sent by

Sends

Supplies

Supplied by

Produced on

Produces

Generated on

Generates

Builds

Built on

Composed of

Goes into

Included on

Includes

Mandatory 1

Mandatory many

Optional many

Many with maximum

Page 3: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Entity Relationship Diagrams

• Purpose: Show the structure (relationship of data elements)

• Can be used in multiple stages of development

• Used to communicate and verify understanding between developers and users, and to document the perceived data model

Page 4: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

ERD Elements• Entities

– Things about which you collect information

• Relationships– Means of association between entities

• Identifiers– Unique attributes of the entity

• Attributes– Characteristic or property of the entity that is of

interest

Page 5: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

ERD Symbols

• Entities: rectangle

• Relationships: diamond (may or may not be used), on a line showing the “cardinality” of the relationship (1 to many), etc.

• Identifiers: Underlined text

• Attributes: Text by the entity (if shown at all on the diagram)

Page 6: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Sample ERDs

1

1

M

1

ORDER

CAN HAVE

PART

SUPPLIER

CAN HAVE

Entity attributes:

ORDER: #, DATE, PART #, QUANTITY

PART: #, DESCRIPTION, UNIT PRICE, SUPPLIER #

SUPPLIER: #, NAME, ADDRESS

Order

Part

Supplier

Page 7: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

ERD Notes

• Relationship connect entities

• Attributes are not technically a part of the diagram but are often included

• ERD is not the same as a relational table design

Page 8: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Entity Sets

• Each individual object is called an entity. A collection of such entities is an entity set.– Example: Joe, Jill, and Mary represent entities.

They are all ascribed to the entity set, PERSON.

– Example: A collection of projects is the project entity set.

Page 9: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Relationship

• Relationship– One interaction between one or more entities– For example: if a person works on a project,

there is a relationship between that person and the project

• Relationship set– A collection of such relationships.– A component in an E-R diagram that represents

a set of relationships with the same properties.

Page 10: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Notes on Entities and Relationships

• We can actually see entities, but we cannot see relationships.– For example:

• Entity sets: Person; project

• Relationship: People work on projects. This becomes the relationship set “Work” Persons

Projects

WorkThe set of people, set of projects and set of working relationships.

Page 11: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Entity-Relationship Structures

Persons

Warehouses

SuppliersParts

ProjectsDepts

Are-In Work-On Use Hold

Supply

More complex relationship:See persons and parts

Projects use partsSuppliers supply partsWarehouses hold parts

Persons are in departmentsPersons work on projects

Page 12: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Entities can have multiple relationships

Companies

Vehicles

Owns Leases

Page 13: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

More than two entity sets can be associated with the same relationship set

Customers

Parts

StoresBuy

Each relationship in this set includes a person, a part boughtby the person, and the store where the purchase was made.

Relationship sets that include only twoentities are known as binary. More thantwo are known as N-ary.

A person, a part bought by the person,and the store where the purchase was made

Page 14: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Identifiers

• One of the attributes of an entity or relationship set is called the identifier

• It has one important property: its values identify unique entities in the entity set.

Page 15: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Identifiers are underlined here

Persons

Projects

Work

The set of people, set of projects and set of working relationships.

PERSON-IDNAMEADDRESS

PERSON-IDPROJECT-IDTIME-SPENT

PROJECT-IDSTART-DATEBUDGET

Page 16: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Convention for Identifiers in Relationships

• Use the identifiers of the entities that participate in the relationship as the relationship identifiers.

• Identifiers are not file keys here. At this stage, they are the identifiers of entities that participate in the relationship.

Page 17: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Cardinality

• The number of relationships in which one entity can appear.

• An entity can appear in:– one (1) relationship;– any variable number (N) of relationships; and– a maximum number of relationships

Page 18: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Cardinality - Example

Persons

Projects

Work

The set of people, set of projects and set of working relationships.

PERSON-IDNAMEADDRESS

PERSON-IDPROJECT-IDTIME-SPENT

PROJECT-IDSTART-DATEBUDGET

N

M

A persona can appear in more than oneWORK relationship, and so can a project.If there was a limit to the number of times anentity can take part in the relationship, thenN or M would be replaced by the actualmaximum number.

Page 19: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Cardinality - Example

Manager

Projects

Manage

The set of people, set of projects and set of working relationships.

MANAGER-IDNAMEADDRESS

PERSON-IDPROJECT-IDTIME-SPENT

PROJECT-IDSTART-DATEBUDGET

1

N

Here a project has one (1) manager, whereasa manager can manage any number (N) of projects.

Page 20: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Cardinality - Example

Manager

Projects

Manage

The set of people, set of projects and set of working relationships.

MANAGER-IDNAMEADDRESS

PERSON-IDPROJECT-IDTIME-SPENT

PROJECT-IDSTART-DATEBUDGET

1

N

The denotes optional participation on theproject. If it is mandatory, then there is no placed there.

Page 21: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Issues in building an ER-Diagram

• How to choose entities, relationships and attributes

• How to choose names

• What steps should be followed

Page 22: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Choosing Attributes

• Attributes, just like entity and relationship sets, should express simple concepts.

• E-R diagrams should not contain multi-valued or structured attributes– For example:

PERSONSPERSON-IDDATE-OF-BIRTHQULIFICATION* (asterisk means it is multivalued-repeating)ADDRESS(NUMBER, STREET, SUBURB)Non-simple attributes

Addresses has structured attributes.These should be replaced in the final diagramby relationships.

Page 23: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Ex: Removing multi-valued and structured attributes

Persons

ADDRESSESQUALIFICATIONS

HAVE LIVE-AT

PERSON-IDDATE-OF-BIRTH

PERSON-IDNUMBERSTREETSUBURB

NUMBERSTREETSUBURB

PERSON-IDQUALIFICATION

QUALIFICATION

Page 24: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Choosing Object Set Names

• Remember, that one goal of E-R modeling is to produce a model that is easily understood by users as well as computer personnel.– Entity sets are labeled as nouns– Relationship sets are labeled by verbs– Relationship sets are structured as prepositions

when modeling structural relationships

Page 25: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Where to begin

• Start with entity sets

• Look at how entities interact with each other and model this in terms of relationship sets

• Then add cardinality to the system

• Add attributes and choose identifiers

Page 26: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Normalization Highlights

Page 27: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Normalization

• The process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating two factors: redundancy and inconsistent dependency.

Page 28: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Factor 1: Inconsistent Dependency

• Customer table should have customer address but not employee salary who calls on customer

• If customer information is contained in an order file, if the order is canceled, all the customer information could be lost– Solution: create two tables--one table contains

order information and the other table contains customer information.

Page 29: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Factor 2: Redundant Data

• Data exists in more than one place

• Wastes disk space and creates maintenance problems– Example: a staff person changes their telephone

number and every potential customer that person ever worked with has to have the corrected number inserted.

Page 30: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Rules for Database Normalization

• First Normal Form – No repeating groups

• Second Normal Form – Eliminate data redundancy

• Third Normal Form: – Eliminate data not dependent on key

Page 31: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Database Normalization - Example

Employee NameEmployee IDDepartmentDept AddressItem#Item DescriptionItem PriceWarehouse IDWarehouse AddressItem Location in each WarehouseQuantity on Hand in each Warehouse

ISDATADDMOD

STARTING WITH A SET OF DATA ITEMS:

Page 32: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Database Normalization - Example

Employee ID

Employee Name

Department

Dept Address

Item#Item DescriptionItem PriceWarehouse IDWarehouse AddressItem Location in each WarehouseQuantity on Hand in each Warehouse

ISDATADDMOD

1. CLUSTER DATA ITEMS INTO ENTITIES (to become TABLES):

Page 33: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Database Normalization - Example

Item# Description Price WarehouseID Address ItemLocation Quantity on Hand WarehouseID Address ItemLocation Quantity on Hand WarehouseID Address ItemLocation Quantity on Hand WarehouseID Address ItemLocation Quantity on Hand

Item# Description Price

Item# Warehouse ID Address ItemLocation Quantity on Hand

From:

To:

NOTE: Item# propagates down and becomes part of the identifier. Why?

ISDATADDMOD

2. PULL OUT MULTI-VALUED ITEMS or REPEATING GROUPS:

Page 34: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Database Normalization - Example

Item# Description PriceItem# Warehouse ID Item Location Quantity on Hand

From:

To:

Item# Description Price

Item# Warehouse ID Address Item Location Quantity on Hand

Warehouse ID Address

ISDATADDMOD

3. PULL OUT FACTS ABOUT A PORTION OF THE KEY (partial dependency):

Page 35: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Database Normalization - Example

From:

To:Employee ID Employee Name Department Dept

Address

Employee ID Employee Name Department

Department ID Dept Address

What is the “Department” field called in the Employee record?

Why does it remain in the Employee record?

ISDATADDMOD

4. PULL OUT FACTS ABOUT A NON-KEY DATA ITEM (transitive dependency):

Page 36: Entity Relationship Diagrams. Supplier Shipment Item Production Plan Product Master Schedule Sent by Sends Supplies Supplied by Produced on Produces Generated.

Role of data values

• Table components

• Fields vs. values

• Records are related via the values

Customer ID Phone # Contact1445 651-644-90022 Thelma1446 612-624-7566 Robert

Customer Order ID Sales Rep1445 CAD112 J on1449 CAD118 Sara

Customer table

Order table

Relation bydata value