Entity Relationship(ER)Entity Relationship(ER)
DiagramDiagram
 An entity-relationship diagram isAn entity-relationship diagram is
aa data modelingdata modeling technique thattechnique that
creates a graphical representation ofcreates a graphical representation of
the entities, and the relationshipsthe entities, and the relationships
between entities, within anbetween entities, within an
information system.information system.
ER-DiagramER-Diagram
Sample ER-DiagramSample ER-Diagram
 An E-R Diagram shows a database’sAn E-R Diagram shows a database’s
entities and the relationships amongentities and the relationships among
the entities in a symbolic, visual way.the entities in a symbolic, visual way.
 Documents a project or application andDocuments a project or application and
serves as its foundationserves as its foundation
 Clarify the system/application’s featuresClarify the system/application’s features
 Provide a basis for evaluatingProvide a basis for evaluating
development optionsdevelopment options
Purpose of ERDs
Entity:Entity:
A class of persons, places, objects, events, orA class of persons, places, objects, events, or
concepts about which we need to capture and storeconcepts about which we need to capture and store
data.data.
 Named by a singular noun.Named by a singular noun.
PersonsPersons: agency, contractor, customer,: agency, contractor, customer,
department, division, employee,department, division, employee,
instructor, student, supplier.instructor, student, supplier.
PlacesPlaces: sales region, building, room,: sales region, building, room,
branch office, campus.branch office, campus.
ObjectsObjects: book, machine, part, product, raw material, software license,: book, machine, part, product, raw material, software license,
software package, tool, vehicle model, vehicle.software package, tool, vehicle model, vehicle.
EventsEvents: application, award, cancellation, class, flight, invoice, order,: application, award, cancellation, class, flight, invoice, order,
registration, renewal, requisition, reservation, sale, trip.registration, renewal, requisition, reservation, sale, trip.
ConceptsConcepts: account, block of time, bond, course, fund, qualification, stock.: account, block of time, bond, course, fund, qualification, stock.
Components of ERD
Relationship:Relationship:
natural business association that exists between one ornatural business association that exists between one or
more entities.more entities.
The relationship may represent an event that links theThe relationship may represent an event that links the
entities or merely a logical affinity that exists between theentities or merely a logical affinity that exists between the
entities.entities.
Components of ERD Contd:
CardinalityCardinality
The minimum and maximum number of occurrences of oneThe minimum and maximum number of occurrences of one
entity that may be related to a single occurrence of the otherentity that may be related to a single occurrence of the other
entity.entity.
Because all relationships are bidirectional, cardinality mustBecause all relationships are bidirectional, cardinality must
be defined in both directions for every relationship.be defined in both directions for every relationship.
Components of ERD
Bidirectional
AttributeAttribute::
A descriptive property orA descriptive property or
characteristic of an entity.characteristic of an entity.
Synonyms includeSynonyms include elementelement,,
propertyproperty, and, and fieldfield..
Just as a physical studentJust as a physical student
can have attributes, such ascan have attributes, such as
hair color, height, etc., datahair color, height, etc., data
entity has data attributesentity has data attributes
Compound attribute:Compound attribute:
 An attribute that consists ofAn attribute that consists of
other attributes. Synonyms inother attributes. Synonyms in
different data modelingdifferent data modeling
languages are numerous:languages are numerous:
concatenated attribute,concatenated attribute,
composite attribute, and datacomposite attribute, and data
structure.structure.
Components of ERD
Cardinality Notations:Cardinality Notations:
Components of ERD
Degree:
The number of entities that participate in the relationship.The number of entities that participate in the relationship.
Components of ERD
Associative entityAssociative entity::
An entity thatAn entity that
inherits primary keyinherits primary key
from more than onefrom more than one
other entity (calledother entity (called
parents).parents).
Components of ERD
Foreign key:Foreign key:
A primary key of an entity that is used in another entity toA primary key of an entity that is used in another entity to
identify instances of a relationship.identify instances of a relationship.
A foreign key is a primary key of one entity that isA foreign key is a primary key of one entity that is
contributed to (duplicated in) another entity to identifycontributed to (duplicated in) another entity to identify
instances of a relationship.instances of a relationship.
A foreign key always matches the primary key in the anotherA foreign key always matches the primary key in the another
entityentity
A foreign key may or may not be unique (generally not)A foreign key may or may not be unique (generally not)
The entity with the foreign key is called the child.The entity with the foreign key is called the child.
The entity with the matching primary key is called theThe entity with the matching primary key is called the
parent.parent.
Components of ERD
Parent entity
A data entity that contributes one or more attributes to
another entity, called the child. In a one-to-many relationship
the parent is the entity on the "one" side.
Child entity
A data entity that derives one or more attributes from
another entity, called the parent. In a one-to-many
relationship the child is the entity on the "many" side.
Components of ERD
The steps involved in creating an ERD are:
Identify the entities.
Determine all significant interactions.
Analyze the nature of the interactions.
Draw the ERD.
ERD Steps
 A good data model is simple.A good data model is simple.
 Data attributes that describe any given entityData attributes that describe any given entity
should describe only that entity.should describe only that entity.
 Each attribute of an entity instance can haveEach attribute of an entity instance can have
only one value.only one value.
 A good data model is essentially non-redundant.A good data model is essentially non-redundant.
 Each data attribute, other than foreign keys,Each data attribute, other than foreign keys,
describes at most one entity.describes at most one entity.
 Look for the same attribute recorded moreLook for the same attribute recorded more
than once under different names.than once under different names.
 A good data model should be flexible andA good data model should be flexible and
adaptable to future needs.adaptable to future needs.
What is a Good Data Model?

PHP mysql Er diagram

  • 2.
  • 3.
     An entity-relationshipdiagram isAn entity-relationship diagram is aa data modelingdata modeling technique thattechnique that creates a graphical representation ofcreates a graphical representation of the entities, and the relationshipsthe entities, and the relationships between entities, within anbetween entities, within an information system.information system. ER-DiagramER-Diagram
  • 4.
  • 5.
     An E-RDiagram shows a database’sAn E-R Diagram shows a database’s entities and the relationships amongentities and the relationships among the entities in a symbolic, visual way.the entities in a symbolic, visual way.  Documents a project or application andDocuments a project or application and serves as its foundationserves as its foundation  Clarify the system/application’s featuresClarify the system/application’s features  Provide a basis for evaluatingProvide a basis for evaluating development optionsdevelopment options Purpose of ERDs
  • 6.
    Entity:Entity: A class ofpersons, places, objects, events, orA class of persons, places, objects, events, or concepts about which we need to capture and storeconcepts about which we need to capture and store data.data.  Named by a singular noun.Named by a singular noun. PersonsPersons: agency, contractor, customer,: agency, contractor, customer, department, division, employee,department, division, employee, instructor, student, supplier.instructor, student, supplier. PlacesPlaces: sales region, building, room,: sales region, building, room, branch office, campus.branch office, campus. ObjectsObjects: book, machine, part, product, raw material, software license,: book, machine, part, product, raw material, software license, software package, tool, vehicle model, vehicle.software package, tool, vehicle model, vehicle. EventsEvents: application, award, cancellation, class, flight, invoice, order,: application, award, cancellation, class, flight, invoice, order, registration, renewal, requisition, reservation, sale, trip.registration, renewal, requisition, reservation, sale, trip. ConceptsConcepts: account, block of time, bond, course, fund, qualification, stock.: account, block of time, bond, course, fund, qualification, stock. Components of ERD
  • 7.
    Relationship:Relationship: natural business associationthat exists between one ornatural business association that exists between one or more entities.more entities. The relationship may represent an event that links theThe relationship may represent an event that links the entities or merely a logical affinity that exists between theentities or merely a logical affinity that exists between the entities.entities. Components of ERD Contd:
  • 8.
    CardinalityCardinality The minimum andmaximum number of occurrences of oneThe minimum and maximum number of occurrences of one entity that may be related to a single occurrence of the otherentity that may be related to a single occurrence of the other entity.entity. Because all relationships are bidirectional, cardinality mustBecause all relationships are bidirectional, cardinality must be defined in both directions for every relationship.be defined in both directions for every relationship. Components of ERD Bidirectional
  • 9.
    AttributeAttribute:: A descriptive propertyorA descriptive property or characteristic of an entity.characteristic of an entity. Synonyms includeSynonyms include elementelement,, propertyproperty, and, and fieldfield.. Just as a physical studentJust as a physical student can have attributes, such ascan have attributes, such as hair color, height, etc., datahair color, height, etc., data entity has data attributesentity has data attributes Compound attribute:Compound attribute:  An attribute that consists ofAn attribute that consists of other attributes. Synonyms inother attributes. Synonyms in different data modelingdifferent data modeling languages are numerous:languages are numerous: concatenated attribute,concatenated attribute, composite attribute, and datacomposite attribute, and data structure.structure. Components of ERD
  • 10.
  • 11.
    Degree: The number ofentities that participate in the relationship.The number of entities that participate in the relationship. Components of ERD
  • 12.
    Associative entityAssociative entity:: Anentity thatAn entity that inherits primary keyinherits primary key from more than onefrom more than one other entity (calledother entity (called parents).parents). Components of ERD
  • 13.
    Foreign key:Foreign key: Aprimary key of an entity that is used in another entity toA primary key of an entity that is used in another entity to identify instances of a relationship.identify instances of a relationship. A foreign key is a primary key of one entity that isA foreign key is a primary key of one entity that is contributed to (duplicated in) another entity to identifycontributed to (duplicated in) another entity to identify instances of a relationship.instances of a relationship. A foreign key always matches the primary key in the anotherA foreign key always matches the primary key in the another entityentity A foreign key may or may not be unique (generally not)A foreign key may or may not be unique (generally not) The entity with the foreign key is called the child.The entity with the foreign key is called the child. The entity with the matching primary key is called theThe entity with the matching primary key is called the parent.parent. Components of ERD
  • 14.
    Parent entity A dataentity that contributes one or more attributes to another entity, called the child. In a one-to-many relationship the parent is the entity on the "one" side. Child entity A data entity that derives one or more attributes from another entity, called the parent. In a one-to-many relationship the child is the entity on the "many" side. Components of ERD
  • 15.
    The steps involvedin creating an ERD are: Identify the entities. Determine all significant interactions. Analyze the nature of the interactions. Draw the ERD. ERD Steps
  • 16.
     A gooddata model is simple.A good data model is simple.  Data attributes that describe any given entityData attributes that describe any given entity should describe only that entity.should describe only that entity.  Each attribute of an entity instance can haveEach attribute of an entity instance can have only one value.only one value.  A good data model is essentially non-redundant.A good data model is essentially non-redundant.  Each data attribute, other than foreign keys,Each data attribute, other than foreign keys, describes at most one entity.describes at most one entity.  Look for the same attribute recorded moreLook for the same attribute recorded more than once under different names.than once under different names.  A good data model should be flexible andA good data model should be flexible and adaptable to future needs.adaptable to future needs. What is a Good Data Model?