bordoloi cmis 450 database design dr. bijoy bordoloi entity relationship (e-r) model
TRANSCRIPT
BordoloiBordoloi
CMIS 450 Database DesignCMIS 450 Database DesignDr. Bijoy BordoloiDr. Bijoy Bordoloi
Entity Relationship (E-R) ModelEntity 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
BordoloiBordoloi
E-R Model ConstructsE-R Model Constructs
• EntitiesEntities
• RelationshipsRelationships
• CardinalityCardinality
• AttributesAttributes
• Sub-entities (EER)Sub-entities (EER)
• ExamplesExamples
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
BordoloiBordoloi
Entity TypesEntity Types
DEPARTMENT
EMPLOYEE
PROJECT
SUPPLIER
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
BordoloiBordoloi
AttributesAttributes
EMPLOYEE
EMP-ID SS-NUM EMP- NAME PHONE
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
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
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)
BordoloiBordoloi
Inappropriate entities
System userSystem user System outputSystem output
Appropriate entities
Figure 3-4
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
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
BordoloiBordoloi
Dependent and Independent EntitiesDependent and Independent Entities
• ExamplesExamples
OFFERING COURSE
TASK PROJECT
DEPENDS ON
DEPENDS ON
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
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)
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
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
BordoloiBordoloi
Ternary RelationshipTernary Relationship
• The relationship involves three entities The relationship involves three entities
COMPANY
PRODUCT
AGENTSELL
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
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.
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
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
BordoloiBordoloi
CardinalityCardinality
EMPLOYEE DEPARTMENTWORK-IN
ONE DEPARTMENTEACH EMPLOYEE
MANY EMPLOYEES EACH DEPARTMENT
MANY ONE
BordoloiBordoloi
Examples of CardinalityExamples of Cardinality
EMPLOYEE DEPARTMENT
N 1WORKS-IN
E1
E2
E3
E4
D1
D2
D3
D4
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
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
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)
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
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