entity relationship diagrams 1. basic elements and rules

29
Entity Relationship Diagrams 1. Basic Elements and Rules

Upload: christopher-mcbride

Post on 26-Mar-2015

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Entity Relationship Diagrams 1. Basic Elements and Rules

Entity Relationship Diagrams

1. Basic Elements and Rules

Page 2: Entity Relationship Diagrams 1. Basic Elements and Rules

Software Analysis & Design

ER Model contains detailed descriptions of:

What are the entities and relationships in the enterprise?

What information about these entities and relationships should we store in the database?

What are the integrity constraints or business rules that hold?

Page 3: Entity Relationship Diagrams 1. Basic Elements and Rules

Data modelling(ERD) vs Process modelling(DFD)

Process modelling (i.e. DFD) shows data stores, how, where, when data are used or changed in an IS

Data modelling (i.e ER) shows definition, structure, and relationship within the data

Page 4: Entity Relationship Diagrams 1. Basic Elements and Rules

Why data model is most important part of the statement of SW requirement?

Characteristics of data captured during data modelling are crucial in design of DB, program, computer screen, and reports

Data rather than processes are the most complex aspects of many modern IS so require a central role in structuring system requirement

The characteristics of data (length, format, relationship) are reasonably permanen. The paths of data flow are quite dynamic.

Structural information about data is essensial for automatic generation of programs

Page 5: Entity Relationship Diagrams 1. Basic Elements and Rules

Conceptual Data Modeling and the E-R Diagram

Goal Capture as much of the meaning of the data as

possible

A better design that is scalable and easier to maintain

Page 6: Entity Relationship Diagrams 1. Basic Elements and Rules

Introduction to Entity-Relationship (E-R) Modeling

Notation uses three main constructs Data entities Attributes Relationships

Entity-Relationship (E-R) Diagram A detailed, logical representation of the

entities, associations and data elements for an organization or business

10.610.6

Page 7: Entity Relationship Diagrams 1. Basic Elements and Rules

Entity-Relationship (E-R) ModelingKey Terms

Entity A person, place, object, event or concept

in the user environment about which the organization wishes to maintain data

Represented by a rectangle in E-R diagrams

Attribute A named property or characteristic of an

entity that is of interest to an organization

10.710.7

Page 8: Entity Relationship Diagrams 1. Basic Elements and Rules

Entity-Relationship (E-R) ModelingKey Terms

Candidate keys and identifiers Attribute (or combination of attributes) that

uniquely identifies each instance of an entity type

Page 9: Entity Relationship Diagrams 1. Basic Elements and Rules

Notation Guide

ENTITY

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

Page 10: Entity Relationship Diagrams 1. Basic Elements and Rules

… Notation Guide

ATTRIBUTE

KEY ATTRIBUTE

MULTIVALUED ATTRIBUTE

DERIVED ATTRIBUTE

COMPOSITE ATTRIBUTE

__________

. . .

Page 11: Entity Relationship Diagrams 1. Basic Elements and Rules

E1E1 R E2E21 N

… Notation Guide

1:N FOR E1:E2 IN R

Page 12: Entity Relationship Diagrams 1. Basic Elements and Rules

ER Diagram Basics

RelationshipRelationship

AttributesAttributes

EntityEntity

Product

Keeps

Store

descrip

qty

price

pname

manager

Locations

sname

Page 13: Entity Relationship Diagrams 1. Basic Elements and Rules

Entity

Real-world object distinguishable from other objects (e.g a student, car, job, subject, building ...)

An entity is described using a set of attributes The same entity may have different prominence in

different scenario– In the Company database, an employee’s car is of lesser importance– In the Department of Transportation’s registration database, cars may be the most important concept– In both cases, cars will be represented as entities; but with different levels of detail

Page 14: Entity Relationship Diagrams 1. Basic Elements and Rules

Attributes

Key Attributes Value Sets of Attributes Null Valued Attributes Attribute Types

– Composite Vs. Simple Attributes– Single-valued Vs. Multi-valued Attributes– Derived Vs. Stored Attributes

NotationNotation

Page 15: Entity Relationship Diagrams 1. Basic Elements and Rules

Key Attributes

Key (or uniqueness) constraints are applied to entity types

Key attribute’s values are distinct for each individual entity.

A key attribute has its name underlined inside the oval

Multiple keys are possible

EMPLOYEE

SSN

Page 16: Entity Relationship Diagrams 1. Basic Elements and Rules

Null Valued Attributes

A particular entity may not have an applicable value for an attribute

Type of Null Values– Not Applicable– Unknown– Missing

Page 17: Entity Relationship Diagrams 1. Basic Elements and Rules

Composite Vs. Simple Attributes

Composite attributes can be divided into smaller parts which represent simple attributes with independent meaning

Simple Attribute: Aircraft-Type Complex Attribute: Aircraft-Location

which is comprised of :Aircraft-LatitudeAircraft-LongitudeAircraft-Altitude

Notation

Page 18: Entity Relationship Diagrams 1. Basic Elements and Rules

Simple attributes can either be single-valuedor multi-valued

Single-valued: Gender = F Notation

Multi-valued: Degree = {BSc, MTech} Notation

Single Vs. Multivalued Attributes

Page 19: Entity Relationship Diagrams 1. Basic Elements and Rules

Derived Vs. Stored Attributes

Some attribute values can be derived fromrelated attribute values: Age ® Date - B-day Y-Sal ® 12 * M-Sal

EMPLOYEE

M-sal

B-days Y-sal

Age

NotationNotation

Page 20: Entity Relationship Diagrams 1. Basic Elements and Rules

Derived Vs. Stored Attributes

Some attribute values can be derived from attributed values of related entities

total-value = sum (qty * price)

Order

Item price

qty

Total-Value

Page 21: Entity Relationship Diagrams 1. Basic Elements and Rules

Representing Attributes

Parenthesis ( ) for composite attributes Brackets { } for multi-valued attributes

Assume a person can have more than one residence and each residence can have multiple telephones

{AddressPhone ({ Phone ( AreaCode,PhoneNum ) }, Address (StreetAddresss (Number, Street, AptNo),

City,State,PostalCode) ) }

Page 22: Entity Relationship Diagrams 1. Basic Elements and Rules

Entity-Relationship (E-R) ModelingKey Terms

Relationship An association between the instances of

one or more entities that is of interest to the organization

Relationships are always labeled with verb phrases

Page 23: Entity Relationship Diagrams 1. Basic Elements and Rules

Naming and Defining Relationships Relationship name is a verb phrase Avoid vague names Guidelines for defining relationships

Definition explains what action is being taken and why it is important

Give examples to clarify the action Optional participation should be explained Explain reasons for any explicit maximum

cardinality

Page 24: Entity Relationship Diagrams 1. Basic Elements and Rules

Relationship Degree

The degree of a relationship type is the number of participating entity types– 2 entities: Binary Relationship 3 entities: Ternary Relationship– Same entity type could participate in multiple relationship types

PartPart

SupplierSupplier SupplySupply ProjectProject

EmployeesEmployees

DepartmentsDepartments

Works_InWorks_In

Assigned_toAssigned_to

TernaryTernary

MultipleMultiple

BinaryBinary

Page 25: Entity Relationship Diagrams 1. Basic Elements and Rules

Entity Roles

Each entity type thatparticipates in a relationshiptype plays a particular rolein the relationship type

The role name signifies therole that a participatingentity from the entity typeplays in each relationshipinstance, i.e. it explains whatthe relationship means

Employees

Works_InWorks_In

Departments

employeremployer

workerworker

RoleRoleNamesNames

Page 26: Entity Relationship Diagrams 1. Basic Elements and Rules

Relationship Constraints

What are Relationship Constraints ? Constraints on the relationship type limit the

possible combination of entities that may participate in the corresponding relationship set

Page 27: Entity Relationship Diagrams 1. Basic Elements and Rules

Possible Relations

1–to-1 (1 : 1)– Both entities can participate in only one relationship instance

1-to-Many, Many-to-1(1 : N, N : 1)– One entity can participate in many relationship instances

Many-to-Many (N: M)– Both entities can participate in many relationship instance

.

.

.

.

.

.

.1- to - Many1- to - Many

.

.

.

.

.

.

.

Many - to - Many - to - 11

.

.

.

.

.

.

1-to-11-to-1

.

.

.

.

.

.

.Many-to-ManyMany-to-Many

Page 28: Entity Relationship Diagrams 1. Basic Elements and Rules

Example Cardinality Constraints

How many Employees can work in a Department? One employee can work in only one departmentHow many Employees can be employed by a Department? One department can employ many employeesHow many managers can a department have? One department can have only one managerHow many departments can an employee manage? One employee can have manage only one department

Page 29: Entity Relationship Diagrams 1. Basic Elements and Rules

Representing Relations

One employee can work in only one departmentOne department can employ many employeesOne department can have only one manager

One employee can manage only one department

N 1

1 1

Employees

Works_InWorks_In

DepartmentDepartmentss

ManagesManages