6.2 Entity-Relationship (E-R) Diagrams
-
Upload
athrey-vinay -
Category
Documents
-
view
230 -
download
0
description
Transcript of 6.2 Entity-Relationship (E-R) Diagrams
DatabasesDatabases
Entity-Relationship (E-R) Entity-Relationship (E-R) DiagramsDiagrams
Learning ObjectivesLearning Objectives
Draw entity-relationship (E-R) diagrams to represent data models diagrammatically.
Design simple relational databases to the third normal form (3NF).
Data Modelling termsData Modelling terms
Entity:Entity: An object, person, event or ‘thing’ a data An object, person, event or ‘thing’ a data
model requires data to be recorded about. model requires data to be recorded about.
AttributeAttribute A property / characteristic of an entity.A property / characteristic of an entity. A field (column) in a database table.A field (column) in a database table.
RelationshipRelationship An association or link between two entities.An association or link between two entities.
Entity-Relationship (E-R) Entity-Relationship (E-R) DiagramsDiagrams (Entity or data model)(Entity or data model)
A diagrammatic means of showing a data A diagrammatic means of showing a data model / database.model / database.
Illustrates the relationships between Illustrates the relationships between entities in the database and attributes of entities in the database and attributes of each entity.each entity.
Example Data ModelExample Data Model
Every student in a school belongs to a Every student in a school belongs to a form.form.
Every student achieves many exam Every student achieves many exam grades.grades.
Every form has a form tutor and all the Every form has a form tutor and all the form tutors are members of the teaching form tutors are members of the teaching body.body.
Entities & their relationships in this Entities & their relationships in this example data modelexample data model
STUDENTSTUDENT Many students can be in a FORM.Many students can be in a FORM. Many STUDENTs can achieve many grades.Many STUDENTs can achieve many grades.
GRADEGRADE Many GRADEs can be achieved by many STUDENTs.Many GRADEs can be achieved by many STUDENTs.
FORMFORM One form for many students (students cannot be members of more One form for many students (students cannot be members of more
than one form).than one form). A FORM can only have one TUTOR.A FORM can only have one TUTOR.
TUTORTUTOR A TUTOR can only be in one FORM.A TUTOR can only be in one FORM. Many TUTORS can be in the teaching body. Many TUTORS can be in the teaching body.
TEACHING BODYTEACHING BODY There is only one There is only one TEACHING BODYTEACHING BODY(teaching body) for all TUTORs.(teaching body) for all TUTORs.
N.B. All entities are written in the singular.
Symbols for relationships between Symbols for relationships between entitiesentities
one-to-one one-to-one represented byrepresented by
one-to-manyone-to-many represented byrepresented by
many-to-onemany-to-one represented byrepresented by
many-to-manymany-to-many represented byrepresented by
ER diagram for example data model ER diagram for example data model (not in 3NF (not in 3NF – see next slides for an explanation– see next slides for an explanation))
STUDENT FORM
TUTORTEACHING
BODY
GRADEachieved
by
achieves members of
has
has
has responsibility for
is a member
contains
Forming Relationships between Forming Relationships between EntitiesEntities
1.1. Try many to many.Try many to many.
2.2. If that doesn’t work then try many to one.If that doesn’t work then try many to one.
3.3. If that doesn’t work try one to many.If that doesn’t work try one to many.
4.4. If that doesn’t work then it has to be one to If that doesn’t work then it has to be one to one.one.
Note: Note: I suggest this order of attempt as it helps avoid I suggest this order of attempt as it helps avoid
problems.problems.
Database NormalizationDatabase Normalization
A technique for designing relational A technique for designing relational database tables to minimize duplication of database tables to minimize duplication of information which can lead to information which can lead to inconsistencies, leading to a loss of data inconsistencies, leading to a loss of data integrity.integrity.
Third Normal Form (Third Normal Form (3NF3NF) eradicates (or at ) eradicates (or at least minimizes) any data duplication.least minimizes) any data duplication.
To change an ER diagram into To change an ER diagram into Third Normalised Form (Third Normalised Form (3NF3NF))
STUDENT FORM
TUTORTEACHING
BODY
GRADEachieved
by
achieves members of
has
has
has responsibility for
is a member
contains
One-to-one relationships should be removedOne-to-one relationships should be removed (but not all mark schemes appear to force this but I suggest you (but not all mark schemes appear to force this but I suggest you always do so anyway).always do so anyway).
•Removed by removing one of the entities and Removed by removing one of the entities and joining it to the entity that is left.joining it to the entity that is left.
ExampleExample
No many-to-many relationships.No many-to-many relationships.•Removed by placing a Removed by placing a link link in betweenin between which has a which has a many to onemany to one relationship to each of the other two entities.relationship to each of the other two entities.
ER diagram for example data model ER diagram for example data model in 3NFin 3NF
STUDENT
FORM_TUTOR
GRADE STUDENT/GRADEachieved
by
achieves
has
has responsibility for
is a member
members of
TEACHINGBODY
LINK
Joint entity
Third Normalised Form (Third Normalised Form (3NF3NF))
No many-to-many relationships.No many-to-many relationships. Removed by placing a Removed by placing a link link in betweenin between which which
has a has a many to onemany to one relationship to each of the relationship to each of the other two entities.other two entities.
One-to-one relationships should be One-to-one relationships should be removed removed (but not all mark schemes appear to force this but I (but not all mark schemes appear to force this but I
suggest you always do so anyway)suggest you always do so anyway).. Removed by removing one of the entities and Removed by removing one of the entities and
joining it to the entity that is left.joining it to the entity that is left.
PlenaryPlenary
A sports club runs a number of sports teams.A sports club runs a number of sports teams.
Each team is made up of a number of members Each team is made up of a number of members of the club and each member may play for more of the club and each member may play for more than one team. Each team has a number of than one team. Each team has a number of coaches, but the coach’s job is so time coaches, but the coach’s job is so time consuming that each coach can only coach one consuming that each coach can only coach one team.team.
Represent the above information on an entity Represent the above information on an entity relation (ER) diagram, in 3rd normal form, relation (ER) diagram, in 3rd normal form, stating the primary key for each entity. stating the primary key for each entity.
PlenaryPlenary