The+Entity Relationship+Model

33
The Entity- The Entity- Relationship Model Relationship Model MGIS 641 Koç University

description

This ERD entity relationship diagrams discussed

Transcript of The+Entity Relationship+Model

Page 1: The+Entity Relationship+Model

The Entity-Relationship ModelThe Entity-Relationship Model

MGIS 641

Koç University

Page 2: The+Entity Relationship+Model

Learning objectivesLearning objectives Define the terms, entity type, attribute, relationship, cardinality, weak

entity, gerund, generalisation, supertype, subtype, inheritance Draw an entity-relationship (E-R) diagram to represent common business

situations Distinguish between unary, binary & ternary relationships Model multivalued attributes & repeating groups in an E-RD Model simple time-dependent data using time stamps in E-RD Model ISA relationships in an E-RD Define four basic types of business rules in an E-RD List several advantages of locating business rules in the repository, rather

than in apps. programs

Page 3: The+Entity Relationship+Model

IntroductionIntroduction

E-R model remains the main stream approach for conceptual data modeling– relative ease of use

– CASE tool support

– Entities-relationships natural modeling way in the real world

E-R model used as a tool for communication between end-users & DB designers during analysis phase– used to construct a conceptual data model - representation of the

structure of DB independent of DBMS S/W. row 3 of ISA IS model

– Introduced by Chen no standard notation - evolving

Page 4: The+Entity Relationship+Model

DB development processDB development processPlanning

Analysis

Logical DB design

Physical DB design

Implementation

Enterprise data model

Conceptual data model

Logical data model

Technology model

DB & repositories

Page 5: The+Entity Relationship+Model

Introduction to E-R modelIntroduction to E-R model

E-R model : A detailed, logical representation of the entities, associations & data elements for an organisation/business area

An E-R model is normally expressed as an E-R diagram which is a graphical representation of an E-R model– E-R model may also be used to represent enterprise data model a

well as conceptual data model (detailed E-RD)

– Major constructs of E-R D are entities, relationships & associated attributes

Page 6: The+Entity Relationship+Model

E-R notationE-R notationBasic symbols :

Entity Relationship Primary key Attribute Multivaluedattribute

Gerund

Relationship degree :

Unary BinaryTernary

Optional zero-manycardinality (0,1,2, ..., many)

Mandatory 1 cardinality

Many(M) cardinality (1,2,.. ,many)

Optional 0 or 1 cardinality

Relationship cardinality:

ISA

Class-subclass relationship

Exclusiverelationship

Page 7: The+Entity Relationship+Model

EntitiesEntities Entity type (entity class): A collection of entities that

share common properties or characteristics– e.g. Person : EMPLOYEE, STUDENT

Place : STATE, REGION, COUNTRY

Object : MACHINE, BUILDING

Event : SALE, REGISTRATION

Concept : ACCOUNT, COURSE

EMPLOYEE COURSE ACCOUNT

Entity Instance : A single occurrence of an entity type

Entity Type : EMPLOYEEAttributes :EMPLOYEE NUMBER

NAMEADDRESSCITYSTATEZIP

Instance of EMPLOYEE00-56-7778Ahmet AslanCayir Cad. No.5IstinyeIstanbul80860

Page 8: The+Entity Relationship+Model

AttributesAttributes

Attribute : A named property or characteristic of an entity that is of interest to the organisation– e.g. STUDENT : STUDENTNO., NAME, ADDRESS, PHONE NO.

AUTOMOBILE : VEHICLE ID, COLOUR, WEIGHT

EMPLOYEE : EMPLOYEE NO. , NAME, ADDRESS, SKILL

NAME COLOUR SKILL

Page 9: The+Entity Relationship+Model

Candidate & primary keysCandidate & primary keys Every entity type must have an attribute/set of attributes

that uniquely identifies each instance & clearly distinguishes that instance from other instances of the same type

Candidate key : an attribute/combination of attributes that uniquely identifies each instance of an entity type

e.g. STUDENT NOEntity Type : GAME Entity Type : EMPLOYEE

Attributes Then EMPLOYEE No,

HOME TEAM NAME+ADDRESS => Candidate keys

VISITING TEAM

REFEREE

DATE

RESULT then HOME TEAM + VISTING TEAM =.> Candidate key

– Primary Key : A candidate key selected as the identifier for an entity - may not be null

Page 10: The+Entity Relationship+Model

Primary key selectionPrimary key selection Choose a candidate key which will not change its value over the life

of each instance of the entity type– e.g. NAME+ADDRESS could change

Choose a candidate key such that for each instance of the entity, the attribute/combinations of attributes is guaranteed to have valid values & not to be null

e.g. GAME type DATE may be used but fixture may not be ready Avoid the use of intelligent keys, whose structure indicates

classifications, locations ...– e.g. first two digits may indicate warehouse location, but they may change as

the conditions change => invalid primary key

Consider substituting single-attribute keys for large composite keys– e.g. HOME TEAM+VISITING TEAM => GAME NO

STUDENT NO NAME ADDRESS PHONE NO

STUDENT

Page 11: The+Entity Relationship+Model

Multivalued attributesMultivalued attributes Multivalued attribute : An attribute that

can have more than one value for each entity instance– During conceptual design highlight them– Subsequently normalise entity data - remove

multivalued attributes & place them in a separate entity type

EMPLOYEE NO NAMEADDRESS SKILL

EMPLOYEE

Page 12: The+Entity Relationship+Model

RelationshipsRelationships

Relationship : An association between the instances of one or more entity types that is of interest to the organisation– glue that holds the various E-R model components

together

– e.g. Registrar interested in tracking who has completed what courses => relationship completes

STUDENT COURSECompletes

Many to many

Page 13: The+Entity Relationship+Model

RelationshipsRelationships

STUDENT COURSECompletes

STUDENTNO.

COURSETITLE

DATECOMPLETED

4545-5656 MGIS 641 JUNE 95

5676-7888 MGIS 641 SEPT 95

4545-5656 MGIS 642 OCT 94

Date Completed is not an attribute of STUDENT entity type since Student with No. 4545-5656 has completed courses on different dates. It is not an attribute of COURSE entity type since MGIS 641 may be completed on different dates.It is a property of Completes relationship.

DATE COMPLETED

Page 14: The+Entity Relationship+Model

Degree of relationshipDegree of relationship

Degree of a relationship : No. of entities that participate in that relationship– three common type of relationships

Unary Binary Ternary

– e.g. Completes relationship between STUDENT & COURSE is a degree two relationship as it involves two entity types.

Page 15: The+Entity Relationship+Model

Unary relationshipUnary relationship Unary (recursive) relationship : relationship between the

instances of one entity type

EMPLOYEE Manages

QUANTITY

ITEMHas

ComponentsPERSONis

marriedto

One-to-One One-to-many Many-to-many

A

V X Y

U V

(1) (1) (2)

(2)(3)

B

X Y Z(2) (1) (1)

V W (2)(1)U V (2)(3)

Page 16: The+Entity Relationship+Model

Binary relationshipBinary relationship Binary relationship : Relationship between

the instances of two entity classes.– Most common type of relationship encountered

STUDENT COURSERegisters

PRODUCT LINE PRODUCTContains

EMPLOYEE PARKING PLACEAssignedIs

for

One-to-One

One-to-many

Many-to-many

Page 17: The+Entity Relationship+Model

Ternary relationshipTernary relationship Ternary relationship : Simultaneous relationship

among the entities of three entity types

QUANTITY

VENDOR WAREHOUSE

PART

Ships

Page 18: The+Entity Relationship+Model

GerundsGerunds Many-to-many relationships may have attributes => they may

be entities in disguise Gerund (composite entity) : A many-to-many relationship

that a data modeler chooses to model as an entity type with several associated one-to-many relationships with other entity types

QUANTITY

VENDORWAREHOUSE

PART

SHIPMENT

SHIPMENT NO

Page 19: The+Entity Relationship+Model

GerundsGerunds In a binary relationship; relationship may be represented as

a gerund or entity For ternary/higher order relationships if any of the

relationships is not “many “ then relationship cannot be shown as an entity

LOCATION TREATMENT

PATIENT

ADMINISTER

LOCATION TREATMENT

PATIENT

ADMINISTER

PATIENT must always beadministered a givenTREATMENT in the samelocation

Business rule :

lost business rule ! Three binary relationships <>A ternary relationship

Page 20: The+Entity Relationship+Model

Cardinalities in relationshipsCardinalities in relationships

Cardinality : The number of instances of an entity type that can (must) be associated with each instance of any other entity type

MOVIE MOVIE COPYIs Stocked as

One-to-many

Page 21: The+Entity Relationship+Model

Minimum & maximum cardinalitiesMinimum & maximum cardinalities Minimum cardinality : Minimum no. of instances of an

entity type that may be associated with each instance of any other entity type

Maximum cardinality : Maximum no. of instances of an entity type that may be associated with each instance of any other entity type

MOVIE MOVIE COPYIs Stocked as

One-to-many

minimum =0

max = manymax = one

minimum = one

(optional)(mandatory)

Page 22: The+Entity Relationship+Model

examples of cardinalitiesexamples of cardinalities

PATIENT PATIENT HISTORYHas

Mandatory cardinalities

EMPLOYEE PROJECTIs Assigned to

One optional one mandatory

3

PERSONIs

married

to

Optional cardinalities

Page 23: The+Entity Relationship+Model

Existence dependencyExistence dependency Existence dependency : An instance of an entity type

cannot exist without the existence of an instance some other (related) entity– Existence dependency - result of mandatory one cardinality

Weak entity : An entity type that has an existence dependency

MOVIE MOVIE COPYIs Stocked as

Page 24: The+Entity Relationship+Model

Identifying relationshipIdentifying relationship Identifying relationship : A relationship in which the

primary key of the parent entity is used as part of the primary key of dependent (child) entity

MOVIE MOVIE COPYIs Stocked as

MOVIE NO MOVIE NAME MOVIE NO COPY NO

Two benefits of an identifying relationship :1) Data integrity. Existence dependencies are enforced since the primary keysis shared - a weak entity cannot exist unless the parent entity exists2) Ease of access of dependent entity. e.g. if Movie No + Copy No known movie copy can be located.

Page 25: The+Entity Relationship+Model

Modeling multivalued attributesModeling multivalued attributes During later stages of conceptual design multi-valued

attributes are removed from the entities - converted to a separate entity

EMPLOYEE NO NAMEADDRESS SKILL

EMPLOYEE

EMPLOYEE NO NAMEADDRESS

EMPLOYEE Has

SKILL NAME

SKILL

Page 26: The+Entity Relationship+Model

Repeating groupsRepeating groups Repeating Group : A Set of two or more multivalued attributes that are

logically related.

PATIENT NONAME ADDRESS

PATIENT

DATE OF VISIT SYMPTOMPHYSICIAN

PATIENT CHART

Patient No : 554545Patient Name : OAYAddress :K.U. Cayir Cd.

Date of VisitVisit Physician Symptom1/5/96 Orkun Cold2/5/96 Utku Fever3/5/96 Arzu Soar Throat

Page 27: The+Entity Relationship+Model

Repeating Group RemovedRepeating Group Removed

PATIENT NO NAME ADDRESS

PATIENT

DATE OF VISIT SYMPTOMPHYSICIAN

PATIENT HISTORY

PATIENT NO

Has

Page 28: The+Entity Relationship+Model

Modeling Time Dependent DataModeling Time Dependent Data Time Stamp : A time value that is associated with any

data value

PRODUCT NOPRICE EFFECTIVE DATE

PRODUCT

PRODUCT NOPRICE EFFECTIVE DATE

PRODUCT PRICE HISTORY

PRODUCT NO

Has

Page 29: The+Entity Relationship+Model

GeneralisationGeneralisation Generalisation: The concept that some entities are subtypes of other

more general entities. Categorisation: The concept that the entity comes comes in various

subtypes. Supertype : A generic entity type that is subdivided into subtypes. Subtype : A subset of a supertype that shares common attributes.

EMPLOYEE NO NAME ADDRESS PHONE NO

EMPLOYEE

EMPLOYEE NO HR RATE

HRLY EMPLOYEE

EMPLOYEE NO MTH LY SALARY

SLRD EMPLOYEE

ISA ISA

Page 30: The+Entity Relationship+Model

ISA Relationship : The relationship between each subtype and its supertype

Exclusive relationship : The subtypes of a supertype are mutually exclusive, and

each instance of the supertype is categorised as exactly one subtype.

Inheritance : When entity types are arranged in a hierarchy, each entity type

assumes the attributes and methods of its ancestors.(e.g. EMPLOYEE : SSN,

NAME , ADDRESS ; WORKER :SSN, DEPT ; MANAGER: SSN, TITLE)

Exhaustive Subtype : (Not)All subtypes are defined for a supertype.

Non-Exhaustive Subtype : Not all subtypes are defined for a supertype

Non-Exclusive subtype : Subtypes may overlap, and an instance of of the

supertype may simultaneously belong to more than one subtype.

Page 31: The+Entity Relationship+Model

Business RulesBusiness Rules

Business Rules : Specifications that preserve the integrity of the

logical data model.

1)Entity Integrity : Each instance of an entity type must have a non Null

unique identifier - Primary Key.

2)Referential Integrity Rules : Rules concerning the relationships

between entity types.

3) Domains: Constraints on valid values for attributes.

4) Triggering operations : Other business rules that protect the validity

of attribute values.

Page 32: The+Entity Relationship+Model

DomainsDomains

Domain : Set of values all data types and ranges of values an attribute may assume.

PRODUCT NOAMOUNT DATE & TIME

ACCOUNT WITHDRAWAL

BALANCE

Name: ACCT NO. Name : AMOUNTData Type : Text Data Type : NumericFormat :AA-NNN Format :Fixed two decimalUniqueness : Unique Uniqueness : Non-uniqueNull : No null value Null : No null value

Range : 1M-20 M

Page 33: The+Entity Relationship+Model

Triggering OperationsTriggering Operations

Trigger : An assertion of a business rule that governs the validity of data manipulation operations such as update , delete etc.

PRODUCT NOAMOUNT DATE & TIME

ACCOUNT WITHDRAWAL

BALANCERule: AMOUNT can not exceed ACCOUNT BALANCEEvent : InsertEntity Name : WITHDRAWALCondition : AMOUNT > BALANCEAction : Reject Transaction