entity-relationship (er) modeling. database design process conceptual model logical model external...

38
Entity-Relationship (ER) Modeling

Upload: dallin-dust

Post on 31-Mar-2015

258 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Entity-Relationship (ER) Modeling

Page 2: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Database Design Process

ConceptualModel

LogicalModel

External Model

Conceptual requirements

Conceptual requirements

Conceptual requirements

Conceptual requirements

Application 1

Application 1

Application 2 Application 3 Application 4

Application 2

Application 3

Application 4

External Model

External Model

External Model

Internal Model

Page 3: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Stages in Database Design

• Requirements formulation and analysis

• Conceptual Design -- Conceptual Model

• Implementation Design -- Logical Model

• Physical Design --Physical Model

Page 4: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Database Design Process

• Requirements formulation and analysis– Purpose: Identify and describe the data that

are used by the organization– Results: Metadata identified, Data Dictionary,

Conceptual Model-- ER diagram

Page 5: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Database Design Process

• Requirements Formulation and analysis– Systems Analysis Process

• Examine all of the information sources used in existing applications

• Identify the characteristics of each data element– numeric

– text

– date/time

– etc.

• Examine the tasks carried out using the information• Examine results or reports created using the information

Page 6: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Conceptual ModelingObjective: to produce HIGH-LEVEL DATA MODEL

GOALSGOALS– a complete understanding of the database structure,

meaning (semantics), interrelationships, and constraints– A stable description of the database contents– Usually more expressive and general than data models

of individual DBMSs– Vehicle of communication among database users,

designers, and analysts.

Page 7: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Database Design Process

• Conceptual Model– Merge the collective needs of all applications– Determine what Entities are being used

• Some object about which information is to maintained

– What are the Attributes of those entities?• Properties or characteristics of the entity• What attributes uniquely identify the entity

– What are the Relationships between entities• How the entities interact with each other?

Page 8: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Database Design Process

• Logical Model– How is each entity and relationship

represented in the Data Model of the DBMS• Hierarchic?• Network?• Relational?• Object-Oriented?

Page 9: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Database Design Process

• Physical ( Internal) Model– Choices of index file structure– Choices of data storage formats– Choices of disk layout

Page 10: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Database Design Process

• External Model– User views of the integrated database – Making the old (or updated) applications work

with the new database design

Page 11: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Data Models: History

• Relational Model (1980’s)– Provides a conceptually simple model for data

as relations (typically considered “tables”) with all data visible.

Book ID Title pubid Author id1 Introductio 2 12 The history 4 23 New stuff ab 3 34 Another title 2 45 And yet more 1 5

pubid pubname1 Harper2 Addison3 Oxford4 Que

Authorid Author name1 Smith2 Wynar3 Jones4 Duncan5 Applegate

Subid Subject1 cataloging2 history3 stuff

Book ID Subid1 22 13 34 24 3

Page 12: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Data Models: History

• Object Oriented Data Model (1990’s)– Encapsulates data and operations as

“Objects”

Books(id, title)

Publisher SubjectsAuthors

(first, last)

Page 13: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Intro. to ER Models

• Entity/Relationship approach - one of the most well known modeling methods

• Developed by P.Chen in 1976 - many variations since then

• Data modeling is generally considered the most important component of the systems development process

Page 14: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

A Simple ERD:

Consider the following situation

A customer places an order. The order consists of parts.

Customer

Entity

An Organization about which we wish to maintain

information

Places

Relationship

An Association between Entities

Orders

Another Entity

Contain

Another Relationship

Parts

Altogether, a Database

Entity Relationship Diagrams

Page 15: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Entity type

Weak entity type

Relationship type

IdentifyingRelationship type

Attribute

Key attribute

Multivalued attribute

Derived attribute

Composite attribute

ER NOTATION

Page 16: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Relationship degrees specify number of entity types involved

Entity symbols

A special entity that is also a relationship

Relationship symbols

Relationship cardinalities specify how many of each entity type is allowed

Attribute symbols

Page 17: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Entity

• An Entity is an object in the real world (or even imaginary worlds) about which we want or need to maintain information– Persons (e.g.: customers in a business,

employees, authors)– Things (e.g.: purchase orders, meetings,

parts, companies)

Employee

Page 18: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Inappropriate entities

System userSystem user System outputSystem output

Appropriate entities

Figure 3-4

Page 19: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Identifiers (Keys)

• Identifier (Key) - An attribute (or combination of attributes) that uniquely identifies individual instances of an entity type

• Simple Key versus Composite Key• Candidate Key – an attribute that could be

a key…satisfies the requirements for being a key

Page 20: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Characteristics of Identifiers

• Will not change in value

• Will not be null

• No intelligent identifiers (e.g. containing locations or people that might change)

Page 21: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Attributes

• Attributes are the significant properties or characteristics of an entity that help identify it and provide the information needed to interact with it or use it. (This is the Metadata for the entities.)

Employee

Last

Middle

First

Name SSN

Age

Birthdate

Projects

Page 22: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Figure 3-7 – A composite attribute

An attribute broken into component parts

Page 23: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Weak Entities

• Owe existence entirely to another entity

Order-lineContainsOrder

Invoice #

Part#

Rep#

QuantityInvoice#

Page 24: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Figure 3-9a – Simple key attribute

The key is underlined

Page 25: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Figure 3-9b – Composite key attribute

The key is composed of two subparts

Page 26: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Figure 3-8 – Entity with a multivalued attribute (Skill) and derived attribute (Years_Employed)

Derived from date employed and current date

What’s wrong with this?

Multivalued: an employee can have more than one skill

Page 27: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Relationships

• Relationships are the associations between entities. They can involve one or more entities and belong to particular relationship types

Page 28: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Relationships

ClassAttendsStudent

PartSuppliesproject

partsSupplier

Project

Page 29: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Relationships

ClassAttendsStudent

PartSuppliesproject

partsSupplier

Project

Page 30: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Types of Relationships

• Concerned only with cardinality of relationship

TruckAssignedEmployee

ProjectAssignedEmployee

ProjectAssignedEmployee

1 1

n

n

1

m

Chen ER notation

Page 31: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Other Notations

TruckAssignedEmployee

ProjectAssignedEmployee

ProjectAssignedEmployee

“Crow’s Foot”

Page 32: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Degree of Relationships

• Degree of a relationship is the number of entity types that participate in it–Unary Relationship–Binary Relationship–Ternary Relationship

Page 33: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Degree of relationships – from Figure 3-2

One entity related to another of the same entity type

Entities of two different types related to each other Entities of three

different types related to each other

Page 34: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Cardinality of Relationships

• One-to-One– Each entity in the relationship will have exactly one

related entity

• One-to-Many– An entity on one side of the relationship can have

many related entities, but an entity on the other side will have a maximum of one related entity

• Many-to-Many– Entities on both sides of the relationship can have

many related entities on the other side

Page 35: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements

Cardinality Constraints

• Cardinality Constraints - the number of instances of one entity that can or must be associated with each instance of another entity

• Minimum Cardinality– If zero, then optional– If one or more, then mandatory

• Maximum Cardinality– The maximum number

Page 36: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements
Page 37: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements
Page 38: Entity-Relationship (ER) Modeling. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual requirements