Top Banner
Bordoloi Bordoloi CMIS 450 Database CMIS 450 Database Design Design Dr. Bijoy Bordoloi Dr. Bijoy Bordoloi Entity Relationship (E-R) Entity Relationship (E-R) Model Model
30

Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

Jan 16, 2016

Download

Documents

Marvin Harris
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

CMIS 450 Database DesignCMIS 450 Database DesignDr. Bijoy BordoloiDr. Bijoy Bordoloi

Entity Relationship (E-R) ModelEntity Relationship (E-R) Model

Page 2: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

E-R Modeling and Logical E-R Modeling and Logical Database DesignDatabase Design

The Entity Relationship ModelThe Entity Relationship Model

The Relational ModelThe Relational Model

Transforming E-R Diagrams into RelationsTransforming E-R Diagrams into Relations

NormalizationNormalization

Page 3: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

E-R Model ConstructsE-R Model Constructs

• EntitiesEntities

• RelationshipsRelationships

• CardinalityCardinality

• AttributesAttributes

• Sub-entities (EER)Sub-entities (EER)

• ExamplesExamples

Page 4: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Definition of EntityDefinition of Entity

• An An entity typeentity type is a set of entity instances sharing is a set of entity instances sharing the the samesame common properties (‘attributes’), common properties (‘attributes’), characterized by:characterized by:– Name Name - a noun, e.g., EMPLOYEE- a noun, e.g., EMPLOYEE

– Description Description - defines which instances belong to the entity - defines which instances belong to the entity type Etype E

– IdentifierIdentifier - a property (or a joint set of properties) which - a property (or a joint set of properties) which uniquely identify entity instancesuniquely identify entity instances

• An An entity instanceentity instance is a single identifiable real- is a single identifiable real-world thing, e.g., Jack Sprattworld thing, e.g., Jack Spratt

Page 5: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Entity TypesEntity Types

DEPARTMENT

EMPLOYEE

PROJECT

SUPPLIER

Page 6: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

AttributesAttributes

• Any property of an owner entityAny property of an owner entity

• Attribute typeAttribute type– A set of attribute instances expressing the same A set of attribute instances expressing the same

property of an entity type, e.g., property of an entity type, e.g., GenderGender

• Attribute instanceAttribute instance– A particular property of an individual entity A particular property of an individual entity

instance, e.g., instance, e.g., MaleMale

Page 7: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

AttributesAttributes

EMPLOYEE

EMP-ID SS-NUM EMP- NAME PHONE

Page 8: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

• An attribute (or a joint set of attributes) An attribute (or a joint set of attributes) which uniquely identify the entity which uniquely identify the entity instances instances of an entityof an entity

• An identifier should be:An identifier should be: - Unique and known (must not be ‘NULL’)- Unique and known (must not be ‘NULL’) - Short (preferably)- Short (preferably)

- Stable (preferably) - Stable (preferably)

IdentifierIdentifier

Page 9: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

What would you choose as the What would you choose as the IdentifierIdentifier of the entity type of the entity type

EMPLOYEE?EMPLOYEE?

EMPLOYEE

EMP-ID SS-NUM EMP- NAME PHONE

Page 10: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

What Should an Entity Be?What Should an Entity Be?• SHOULD BE:SHOULD BE:

– An object that will have many instances in the An object that will have many instances in the databasedatabase

– An object that will be composed of multiple An object that will be composed of multiple attributesattributes

– An object that we are trying to modelAn object that we are trying to model– Must have an Must have an identifieridentifier

• SHOULD NOT BE:SHOULD NOT BE:– A user of the database system A user of the database system – An output of the database system (e.g. a report)An output of the database system (e.g. a report)

Page 11: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Inappropriate entities

System userSystem user System outputSystem output

Appropriate entities

Figure 3-4

Page 12: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

• Entity B is existence-dependent on entity A whenEntity B is existence-dependent on entity A when– Some instance of A must exist before B can existSome instance of A must exist before B can exist– If A ceases to exist, B must also cease to existIf A ceases to exist, B must also cease to exist

• An independent entity is not existence-dependent An independent entity is not existence-dependent on any other entityon any other entity

• Independent Entity – Strong EntityIndependent Entity – Strong Entity• Dependent Entity – Weak Entity Dependent Entity – Weak Entity • Diagramming conventionDiagramming convention

Dependent and Independent EntitiesDependent and Independent Entities

Page 13: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

• Typically the identifier of a weak entity is a Typically the identifier of a weak entity is a composite composite identifier which includes the identifier identifier which includes the identifier of the entity which the weak entity is existence-of the entity which the weak entity is existence-dependent upon dependent upon

• Diagramming conventionDiagramming convention

Dependent and Independent EntitiesDependent and Independent Entities

Page 14: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Dependent and Independent EntitiesDependent and Independent Entities

• ExamplesExamples

OFFERING COURSE

TASK PROJECT

DEPENDS ON

DEPENDS ON

Page 15: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

RelationshipsRelationships• An association between two or more entities, An association between two or more entities,

of significance to the enterpriseof significance to the enterprise

• Relationships are named with a verb an Relationships are named with a verb an depicted as lines between entitiesdepicted as lines between entities

SUPPLIERPART

EMPLOYEECOMPANY

SHIP

WORK FOR

Page 16: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

DegreeDegree

• The degree of a relationship is the number of The degree of a relationship is the number of associated entitiesassociated entities

• Relationships are usually of degree 2 (binary) Relationships are usually of degree 2 (binary) - but sometimes can be unary or of higher - but sometimes can be unary or of higher degree (N-ary)degree (N-ary)

Page 17: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Binary RelationshipsBinary Relationships

• The relationship involves at the most only The relationship involves at the most only two entitiestwo entities

SUPPLIER PART

EMPLOYEE COMPANY

SHIP

WORK FOR

Page 18: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Unary RelationshipsUnary Relationships

• Relationships may associate an entity with Relationships may associate an entity with itself, i.e., when an instance of an entity is itself, i.e., when an instance of an entity is related to some other instance(s) of the related to some other instance(s) of the samesame entity. entity.

EMPLOYEEMarried_to

Page 19: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Ternary RelationshipTernary Relationship

• The relationship involves three entities The relationship involves three entities

COMPANY

PRODUCT

AGENTSELL

Page 20: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

• Several relationships may exist between the same Several relationships may exist between the same entitiesentities

• The name and description distinguishes different The name and description distinguishes different relationships between the same entitiesrelationships between the same entities

RelationshipsRelationships

EMPLOYEE DEPARTMENT

MANAGE

FORMERLY WORKED IN

WORK IN

Page 21: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Cardinality ConstraintsCardinality Constraints• A binary relationship (EA binary relationship (E11,E,E22) has two directions, ) has two directions,

left and rightleft and right

• Each direction has cardinality constraints, Each direction has cardinality constraints, described as maximum and mimimu.described as maximum and mimimu.

Page 22: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Cardinality ConstraintsCardinality Constraints

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

• Maximum Cardinality (Maximum Cardinality (can becan be))– The maximum numberThe maximum number

Minimum Cardinality (Minimum Cardinality (must bemust be))– If zero, then optionalIf zero, then optional– If one or more, then mandatoryIf one or more, then mandatory

Page 23: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Maximum CardinalityMaximum Cardinality• The maximum cardinality of a direction EThe maximum cardinality of a direction E11 to E to E22

indicates how many eindicates how many e22’s can match a given e1 ’s can match a given e1

(at most)(at most)

• Cardinality is denoted as MaxLeft - MaxRightCardinality is denoted as MaxLeft - MaxRight– 1-11-1

– 1-N1-N

– N-1N-1

– M-NM-N

Page 24: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

CardinalityCardinality

EMPLOYEE DEPARTMENTWORK-IN

ONE DEPARTMENTEACH EMPLOYEE

MANY EMPLOYEES EACH DEPARTMENT

MANY ONE

Page 25: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Examples of CardinalityExamples of Cardinality

EMPLOYEE DEPARTMENT

N 1WORKS-IN

E1

E2

E3

E4

D1

D2

D3

D4

Page 26: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Examples of CardinalityExamples of Cardinality

1 1

M N

E1

E2

E3

E4

D1

D2

D3

D4

E1

E2

E3

E4

D1

D2

D3

D4

MANAGE

FORMERLY WORKED-IN

Page 27: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Minimum CardinalityMinimum Cardinality

• Minimum cardinality is specified as zero to oneMinimum cardinality is specified as zero to one

EMPLOYEE DEPARTMENT WORK IN

ONE DEPARTMENTEACH EMPLOYEE

ZERO EMPLOYEES EACH DEPARTMENT

ZERO ONE

Page 28: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Minimum CardinalityMinimum Cardinality

• For the purpose of our course, we will use:For the purpose of our course, we will use:

Instructorteaches

One to many (maximum cardinality)

Mandatory Optional (minimum cardinality)

Page 29: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

Summary of CardinalitySummary of Cardinality

• Minimum and maximum cardinality is Minimum and maximum cardinality is specified for each specified for each direction direction of a relationshipof a relationship

• Maximum cardinality is either Maximum cardinality is either one or many one or many for each directionfor each direction

• Minimum cardinality is either Minimum cardinality is either zero or one zero or one for each directionfor each direction

Page 30: Bordoloi CMIS 450 Database Design Dr. Bijoy Bordoloi Entity Relationship (E-R) Model.

BordoloiBordoloi

TerminologyTerminology

• A single-valued relationship (from entity A A single-valued relationship (from entity A to entity B) has maximum cardinality of to entity B) has maximum cardinality of one one (from A to B)(from A to B)

• A multi-valued relationship has maximum A multi-valued relationship has maximum cardinality of cardinality of manymany

• When we speak of single-valued and multi-When we speak of single-valued and multi-valued relationships, a direction is implicitvalued relationships, a direction is implicit