Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Relational Database Lecture 2: Entity-Relationship Modelling
Objectives <ul><li>By the end of this lecture you should be able to: </li></ul><ul><li>Describe how entities, attributes a...
Recap <ul><li>Last lecture we looked at the relational model of data: </li></ul><ul><ul><li>Information Principle, “ All i...
Entity-Relationship Modelling <ul><li>Deciding what data to hold in a database and how to structure it into tables is a  d...
Entities and Entity-types <ul><li>An entity is , “ anything about which we want to store data”. </li></ul><ul><li>We class...
E-R Diagram  <ul><li>In E-R modelling we use a box to represent entity-types:  </li></ul>Student Lecture Lecturer
Relationships and Relationship-types <ul><li>Entities take part in relationships.  We can often identify relationships fro...
E-R Diagram <ul><li>We name relationship-types and depict them on our diagram as diamonds with lines connecting to the app...
Relationship-type Degree <ul><li>The  degree  of the relationship-type has to do with the maximum number of relationships ...
E-R Diagram <ul><li>We extend the relationship diagram to include degrees: </li></ul>Student Lecture Lecturer E-R diagram ...
Participation <ul><li>The  participation constraint  specifies the minimum number of relationships of a given type that an...
E-R Diagram <ul><li>We extend the relationship diagram to include participation: </li></ul>Student Lecture Lecturer E-R di...
Attributes <ul><li>An attribute is a single-valued property of either an entity-type or a relationship-type. </li></ul><ul...
Dealing with multi-valued attributes <ul><li>Note that attributes should be single-valued. If some lectures might be relay...
E-R Diagram Student Lecture Lecturer E-R Diagram for student-lecture-lecturer attends gives M N 1 M surname forenames titl...
Attribute or Entity-type? <ul><li>To decide whether a concept be modelled as an attribute or an entity-type: </li></ul><ul...
Promotion from attribute to entity-type I Lecture time date module length
Promotion from attribute to entity-type I Lecture time date length Belongs to Module code title credits M 1
Promotion from attribute to entity-type I Lecture time date objectives length
Promotion from attribute to entity-type I Lecture time date length Addresses Objectives description M N
Determining components of an E-R Diagram <ul><li>From a description of the Universe of Discourse (UoD): </li></ul><ul><li>...
Example UoD <ul><li>“ Each  module  is identified by a  module_code  and  consists of  a number of  lectures ,  tutorials ...
Summary <ul><li>E-R modelling is a first step towards database design. </li></ul><ul><li>It is a non-trivial design activi...
Upcoming SlideShare
Loading in …5
×

Entity relationship modelling

6,428 views

Published on

Entity relationship modelling

  1. 1. Relational Database Lecture 2: Entity-Relationship Modelling
  2. 2. Objectives <ul><li>By the end of this lecture you should be able to: </li></ul><ul><li>Describe how entities, attributes and relationships are used to model data; </li></ul><ul><li>Decide whether to model a given concept as an entity, attribute or relationship; </li></ul><ul><li>Determine the degree of a relationship; </li></ul><ul><li>Produce an entity relationship diagram based on a simple description of a domain. </li></ul>
  3. 3. Recap <ul><li>Last lecture we looked at the relational model of data: </li></ul><ul><ul><li>Information Principle, “ All information in the database must be cast explicitly in terms of values in relations and in no other way ” EF Codd </li></ul></ul><ul><ul><li>Atomic Attributes </li></ul></ul><ul><ul><li>Primary keys </li></ul></ul><ul><ul><li>Foreign keys </li></ul></ul><ul><ul><li>Referential integrity </li></ul></ul><ul><li>In this lecture we show how to analyse/model data as a first step to designing a relational database </li></ul>
  4. 4. Entity-Relationship Modelling <ul><li>Deciding what data to hold in a database and how to structure it into tables is a design issue. </li></ul><ul><li>Entity-relationship modelling analyses data requirements in a systematic way to help produce a well-designed database. </li></ul><ul><li>E-R modelling should always be completed before you implement your database. </li></ul><ul><li>Everything is modelled in terms of three basic concepts: </li></ul><ul><ul><li>Entities, </li></ul></ul><ul><ul><li>Attributes </li></ul></ul><ul><ul><li>Relationships. </li></ul></ul>
  5. 5. Entities and Entity-types <ul><li>An entity is , “ anything about which we want to store data”. </li></ul><ul><li>We classify entities according to their type: </li></ul><ul><li>Some entities (eg you and I) are more concrete than others (eg a lecture). Entities may be physical objects, events or abstract (for example ‘degree programme’) </li></ul>Lecture This lecture Lecturer Me Student You Entity-type Entity
  6. 6. E-R Diagram <ul><li>In E-R modelling we use a box to represent entity-types: </li></ul>Student Lecture Lecturer
  7. 7. Relationships and Relationship-types <ul><li>Entities take part in relationships. We can often identify relationships from verbs or verb phrases. </li></ul><ul><li>For example </li></ul><ul><ul><li>you are attending this lecture, </li></ul></ul><ul><ul><li>I am giving the lecture. </li></ul></ul><ul><li>As with entities, we classify relationships according to relationship-types: </li></ul><ul><ul><li>A student attends a lecture; </li></ul></ul><ul><ul><li>A lecturer gives a lecture. </li></ul></ul>
  8. 8. E-R Diagram <ul><li>We name relationship-types and depict them on our diagram as diamonds with lines connecting to the appropriate entity-types: </li></ul>Student Lecture Lecturer E-R depiction of entity-types and their relationship-types gives attends
  9. 9. Relationship-type Degree <ul><li>The degree of the relationship-type has to do with the maximum number of relationships of a given type an entity is allowed to take part in. We label relationships-types as 1:1, 1:M or M:N. </li></ul><ul><ul><li>The relationship-type ‘ currently married to’ between one person and another in a law-abiding, monogomous society is 1:1. Each person is allowed to be ‘ currently married’ to at most one person. </li></ul></ul><ul><ul><li>The relationship-type ‘ gives’ between lecturer and lecture could be 1:M or M:N, depending on circumstances for which our database is to be used. </li></ul></ul><ul><ul><li>The relationship-type ‘ attends ’ is M:N. </li></ul></ul>
  10. 10. E-R Diagram <ul><li>We extend the relationship diagram to include degrees: </li></ul>Student Lecture Lecturer E-R diagram extended to show relationship degrees. gives attends M 1 M N
  11. 11. Participation <ul><li>The participation constraint specifies the minimum number of relationships of a given type that an entity may participate in. </li></ul><ul><li>Principally we are interested in the question, “Does every entity of a some type have to take part in a relationship of a given type?” </li></ul><ul><li>For example, it might be considered true that: </li></ul><ul><ul><li>Every lecture has to be given by a lecturer </li></ul></ul><ul><ul><li>Every lecturer has to give at least one lecture </li></ul></ul><ul><ul><li>Every lecture has to be attended by at least one student </li></ul></ul><ul><ul><li>Not every student has to attend a lecture </li></ul></ul>
  12. 12. E-R Diagram <ul><li>We extend the relationship diagram to include participation: </li></ul>Student Lecture Lecturer E-R diagram extended to show relationship degrees. gives attends M 1 M N
  13. 13. Attributes <ul><li>An attribute is a single-valued property of either an entity-type or a relationship-type. </li></ul><ul><ul><li>For example, a lecture might have attributes: time, date, length, place. </li></ul></ul>Lecture time date length place
  14. 14. Dealing with multi-valued attributes <ul><li>Note that attributes should be single-valued. If some lectures might be relayed to lecture theatres other than the one where the lecturer is physically present, then we would model this: </li></ul>Lecture time date length Lecture theatre Takes place in M N
  15. 15. E-R Diagram Student Lecture Lecturer E-R Diagram for student-lecture-lecturer attends gives M N 1 M surname forenames title surname forenames title time date length place Reg_no
  16. 16. Attribute or Entity-type? <ul><li>To decide whether a concept be modelled as an attribute or an entity-type: </li></ul><ul><ul><li>Do we wish to store any information about this concept (other than an identifying name)? </li></ul></ul><ul><ul><li>Is it single-valued? </li></ul></ul>
  17. 17. Promotion from attribute to entity-type I Lecture time date module length
  18. 18. Promotion from attribute to entity-type I Lecture time date length Belongs to Module code title credits M 1
  19. 19. Promotion from attribute to entity-type I Lecture time date objectives length
  20. 20. Promotion from attribute to entity-type I Lecture time date length Addresses Objectives description M N
  21. 21. Determining components of an E-R Diagram <ul><li>From a description of the Universe of Discourse (UoD): </li></ul><ul><li>Underline nouns and noun-phrases </li></ul><ul><ul><li>These are candidates for entity-types </li></ul></ul><ul><li>Underline verbs and verb-phrases </li></ul><ul><ul><li>These are candidates for relationship-types </li></ul></ul><ul><li>Check each entity- and relationship-type for relevance. </li></ul><ul><li>Remove any for which there is only one instance. </li></ul>
  22. 22. Example UoD <ul><li>“ Each module is identified by a module_code and consists of a number of lectures , tutorials and exercise classes . Students are required to attend lectures and tutorials, but exercise classes are optional. Lectures are given either by a member of staff or (occasionally) a postgraduate student . Modules are specified in terms of a list of learning objectives . Each lecture should address one or more of these objectives .” </li></ul>
  23. 23. Summary <ul><li>E-R modelling is a first step towards database design. </li></ul><ul><li>It is a non-trivial design activity that is intellectually demanding, but should not be overlooked. </li></ul><ul><li>This lecture has covered only the basics. See Chen’s paper or Elmasri &Nevathe for more details </li></ul><ul><li>The rules for designing a relational database given an E-R model are straightforward. </li></ul><ul><li>We shall cover these rules in the next lecture. </li></ul>

×