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

Post on 20-Dec-2015

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Entity Relationship Diagrams

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

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

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

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)

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

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

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.

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.

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.

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

Entities can have multiple relationships

Companies

Vehicles

Owns Leases

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

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.

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

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.

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

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.

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.

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.

Issues in building an ER-Diagram

• How to choose entities, relationships and attributes

• How to choose names

• What steps should be followed

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.

Ex: Removing multi-valued and structured attributes

Persons

ADDRESSESQUALIFICATIONS

HAVE LIVE-AT

PERSON-IDDATE-OF-BIRTH

PERSON-IDNUMBERSTREETSUBURB

NUMBERSTREETSUBURB

PERSON-IDQUALIFICATION

QUALIFICATION

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

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

Normalization Highlights

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.

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.

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.

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

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:

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):

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:

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):

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):

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

top related