The Entity-Relationship Model

MGIS 641 Koç University

Learning objectives
q q

q q q

q q q

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 ERD 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

Introduction
q

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

q

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

DB development process
Planning Enterprise data model Analysis Conceptual data model Logical DB design Logical data model Physical DB design Technology model Implementation DB & repositories

Introduction to E-R model
q

q

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

Basic symbols :

E-R notation

Relationshiprimary key P Attribute Multivalued Gerund attribute Relationship degree :

Entity

Unary

Binary Mandatory 1 cardinality

elationship cardinality:

Ternary

ISA Many(M) cardinality Class-subclass relationship (1,2,.. ,many) Exclusive Optional 0 or 1 relationship cardinality Optional zero-many cardinality (0,1,2, ..., many)

Entities
q

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
Instance of EMPLOYEE Entity Type : EMPLOYEE Attributes :EMPLOYEE NUMBER00-56-7778 Ahmet Aslan NAME Cayir Cad. No.5 ADDRESS Istinye CITY Istanbul STATE 80860 ZIP

Attributes
q

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

Candidate & primary keys
q

q

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
q

e.g. STUDENT NO

Entity 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

q

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

Primary key selection

q

q

q

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

q

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

Multivalued attributes
q

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

NAME

ADDRESS

SKILL

EMPLOYEE

Relationships
q

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

Completes Many to many

COURSE

Relationships
STUDENT NO. 4545-5656 5676-7888 4545-5656 COURSE TITLE MGIS 641 MGIS 641 MGIS 642 DATE COMPLETED JUNE 95 SEPT 95 OCT 94

Completed is not an attribute of STUDENT entity type since Student wi 4545-5656 has completed courses on different dates. It is not an attribu RSE entity type since MGIS 641 may be completed on different dates. a property of Completes relationship. DATE COMPLETED STUDENT COURSE

Completes

Degree of relationship
q

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

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

Unary relationship
q

Unary (recursive) relationship : relationship between the instances of one entity type
is married EMPLOYEE to Has

PERSON

Manages

ITEM

Components

One-to-One A V (1)

One-to-many

Many-to-many B QUANTITY

X (1)

Y (2)

X (2)

Y

(1)

Z (1) V (1) W (2)

U (3) V (2)

U (3) V (2)

Binary relationship
q

Binary relationship : Relationship between the instances of two entity classes.
– Most common type of relationship encountered

EMPLOYEE

Is Assigned One-to-One

PARKING PLACE

PRODUCT LINE

Contains One-to-many

PRODUCT

STUDENT

Registers for Many-to-many

COURSE

Ternary relationship
q

Ternary relationship : Simultaneous relationship among the entities of three entity types

QUANTITY

VENDOR

Ships

WAREHOUSE

PART

Gerunds
q q

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-tomany relationships with other entity types
QUANTITY SHIPMENT NO

VENDOR

SHIPMENT

WAREHOUSE

PART

Gerunds
q q

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
ADMINISTER

TREATMENT

Business rule : PATIENT must always be administered a given PATIENT TREATMENT in the same location LOCATION lost business rule ! PATIENT
ADMINISTER

TREATMENT

Three binary relationships <> A ternary relationship

Cardinalities in relationships
q

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

MOVIE

Is Stocked as One-to-many

MOVIE COPY

q

q

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 max = one Is Stocked as One-to-many MOVIE COPY max = many minimum =0 (optional)

Minimum & maximum cardinalities

minimum = one (mandatory)

examples of cardinalities
PATIENT Has PATIENT HISTORY

Mandatory cardinalities EMPLOYEE 3 Is Assigned to PROJECT

One optional one mandatory Is married to

PERSON

Optional cardinalities

Existence dependency
q

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

q

Weak entity : An entity type that has an existence dependency
MOVIE Is Stocked as MOVIE COPY

Identifying relationship
q

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 NO

MOVIE NAME

MOVIE NO

COPY NO

MOVIE

Is Stocked as

MOVIE COPY

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

q

Modeling multivalued attributes design multiDuring later stages of conceptual
valued attributes are removed from the entities converted to a separate entity
NAME ADDRESS SKILL

EMPLOYEE NO

EMPLOYEE

EMPLOYEE NO

NAME

ADDRESS

SKILL NAME

EMPLOYEE

Has

SKILL

Repeating groups
q

Repeating Group : A Set of two or more multivalued attributes that are logically related.
Date of Visit Patient No : 554545 1/5/96 Patient Name : OAY 2/5/96 Address :K.U. Cayir Cd. 3/5/96 PATIENT CHART Visit Physician Symptom Orkun Cold Utku Fever Arzu Soar Throat

PATIENT NO

NAME

ADDRESS

PATIENT

DATE OF VISIT

SYMPTOM

PHYSICIAN

Repeating Group Removed
PATIENT NO NAME ADDRESS PATIENT NO

PATIENT

Has

PATIENT HISTORY

DATE OF VISIT

SYMPTOM

PHYSICIAN

Modeling Time Dependent Data
q

Time Stamp : A time value that is associated with any data value
PRICE EFFECTIVE DATE

PRODUCT NO

PRODUCT

PRODUCT NO

PRICE

EFFECTIVE DATE

PRODUCT

Has

PRICE HISTORY PRODUCT NO

Generalisation
q q

q q

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 EMPLOYEE

PHONE NO

ISA

ISA

HRLY EMPLOYEE

SLRD EMPLOYEE

EMPLOYEE NO

HR RATE

EMPLOYEE NO

MTH LY SALARY

q q

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.

q

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)

q q q

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.

Business Rules
q

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.

Domains
q

Domain : Set of values all data types and ranges of values an attribute may assume.
AMOUNT DATE & TIME

PRODUCT NO

ACCOUNT

WITHDRAWAL

BALANCE
Name: ACCT NO. Data Type : Text Format :AA-NNN Uniqueness : Unique Null : No null value

Name : AMOUNT Data Type : Numeric Format :Fixed two decim Uniqueness : Non-unique Null : No null value Range : 1M-20 M

Triggering Operations
q

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

PRODUCT NO

ACCOUNT

WITHDRAWAL

BALANCE

Rule: AMOUNT can not exceed ACCOUNT BALANCE Event : Insert Entity Name : WITHDRAWAL Condition : AMOUNT > BALANCE Action : Reject Transaction

Sign up to vote on this title
UsefulNot useful