1 / 36

selecting entities

selecting entities. Data Modelling . Objectives At the end of this chapter you should be able to: Discuss the use and features of a data model Define the terms entity and attribute and reference them to corresponding terms in table design

haile
Download Presentation

selecting entities

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. selecting entities

  2. Data Modelling Objectives At the end of this chapter you should be able to: • Discuss the use and features of a data model • Define the terms entity and attribute and reference them to corresponding terms in table design • Select suitable entities and attributes for a given case study • Describe and select suitable primary keys

  3. Entity modelling We need to hold data to meet user requirements. e.g. names, addresses, stock quantities, appointment times etc. We could hold all this data in a single table What would be the disadvantages ? A data model provides us with a way of visually deciding how we might break up the data into chunks so that the data items in a chunk all relate to the same object or entity A data model may be produced using a technique known as entity modelling

  4. Entity modelling The relationships between these entities are then shown on a diagram and we can see the structure of the proposed database The diagram is often called an entity relationship diagram (ERD) The data model consists of the ERD and the accompanying documentation A model in this sense is a selection of features that describe a certain aspect of a system

  5. What is an Entity ? • An entity is anything of significance about which we wish to hold information • Entities can be • real world objects such as Employee, Chair and Car • intangible objects such as Purchase Order, Current Account, and Seat Reservation. These entities should contain all the information that we need to hold in the database

  6. Entities and attributes The requirements of the system are first analysed to find what is significant and what is not Entities are described by a set of attributes An attribute is a data item that can be used to describe the state of an entity

  7. entity name attributes Entities and attributes Example of an Entity

  8. Occurrence An entity will allow us to generate an occurrence or a particular example of an entity. 36285 Brenda Wooltorton Yes 01453 658372

  9. Occurrence Every customer would have values for most, if not all, of these attributes Each entity can potentially give rise to any number of occurrences

  10. Data model and Database • Entity becomes Table • Attribute becomes Field • Occurrence becomes Record

  11. Example table

  12. Example field

  13. Example record

  14. Before selecting entities and attributes Understand the problem domain • Conduct an analysis of the user’s present system and future requirements • Use interviews, existing documentation and observation

  15. Identifying possible entities • Be clear about the context • In this case the context is the selection and booking of courses for staff members • Names of the possible entities must be • expressed in the singular • start with an upper case letter • Picking out the nouns is one way of making up a list of possible entities

  16. SFU example Staffordshire Free University employs a large number of staff who need to keep up to date with a whole variety of subjects. The staff may work in different departments within the university. A system is required that will keep track of bookings made by staff members to go on various training courses. The courses may be internal or external.

  17. SFU example (cont) Each course, whether internal or external, occurs on a number of occasions and staff members are free to choose which offering they wish to take. Each course has a title and it is required to know when they start. Each course offering for the same course will last for the same time and this must be recorded. The course offerings may be at any number of different locations and will only run if there are a minimum number of students booked onto the course offering. Each course offering also has a maximum number of students who are allowed to be booked onto it.

  18. SFU example (cont) The staff are allowed to browse the different courses available and then select the particular course they wish to go on and the offering that suits them best. When a staff member makes a booking the system should record the date on which it was made. Detail of the staff member booking a course offering include the name, job title, date of birth, date appointed and department name. The database should allow the training officer in SFU to see which members of staff are booked onto which courses

  19. Identifying possible entities The list here would be: Staffordshire Free University Staff Subject Department Training Course Number of occasions Course Offering Course Title Start Date Booking Course Duration Location Minimum Student Number Maximum Student Number Student Booking Date Staff Name Job Title Date of Birth Date Appointed Department Name Training Officer

  20. Guidelines for selection of entities Must be something about which we wish to store information in the context of the case study There must be more than one occurrence of each entity Make sure you have an entity and not an attribute. If it is an entity there will be more than one attribute you will want to have for it. It is very common to need to decide if you have an attribute or an entity.

  21. Guidelines for selection of entities Consider if the entity name is vague. It should be specific Call an entity by one name Think of two or three attributes it might contain that we need to operate the system Don’t include the name of the company for which you are performing the data model. The entire E-R diagram is representing the company Don’t expect to get a full list of entities immediately

  22. What have we left? Staff Member Course Booking Course Offering We need to remember that we may add to this list of entities later.

  23. Attributes Each attribute can take on only one value for any one occurrence of that entity If you are putting in an attribute with an ‘s’ on the end – stop and think. This may be an entity in its own right

  24. Guidelines for placing attributes in entities • Each attribute name should be in the singular • If attribute is plural then you must create another entity where you can place that attribute in its singular form • The chosen name should be specific • e.g. choose quantity in stock or order quantity or re-order quantity rather than quantity

  25. Guidelines for placing attributes in entities • Check that you can choose a suitable value for that attribute for a given occurrence • An attribute should be placed in one entity only • Choose the most natural home for its placement • Resist the temptation to put an attribute in more than one place • e.g. customer ID could be placed in the Customer or Order entity

  26. Guidelines for placing attributes in entities • Don’t include attributes whose values may be determined from other attribute values • e.g.For example don’t include Total Value if it is simply the sum of a number of Sub-totals that you are already keeping • Never use the term ‘details’ • Check against the case study for omissions

  27. Entities for Staffordshire Free University example

  28. Worries • a course offering apparently has no details of the course title • a booking does not know for which person or course it is made!

  29. Primary key Uniquely identify each occurrence of an entity by reference to the values of its attributes Choose one or more attributes such that if we know their value we can uniquely identify that occurrence One or more attributes that perform such a function are known as the primary key of that entity

  30. Primary key Sometimes a primary key already exists Choose the minimum number of attributes possible to form the primary key If Customer ID is a unique number such that no two customers can have identical numbers then Customer ID could be a primary key

  31. Primary key Combinations of other attributes would not guarantee a way of uniquely identifying a customer Underline the attribute(s) forming the primary key

  32. Entities for SFU with attributes and primary keys

  33. Placing attributes in more than one entity We may relax our rule of placing an attribute in only one entity if we need it in another entity to form part of a primary key See Course ID for the Course entity and Course ID for Course Offering

  34. Dealing with small items • Can we uniquely identify some small items ? • We need to identify the name of the entity as a type of object • e.g. we might call an entity Stock Item Type and have attributes of Item #, Item Description and Quantity in Stock • Two occurrences then might be: Item # Item Description Quantity in Stock 237654 2” steel nail 4000 421889 4mm bolt 43

  35. Summary Entities are often chosen from nouns in requirements specification Test to see if an entity has two attributes (or more) that we need to know to make our system work Don’t put any single attribute in more than one place

  36. References Software System Development – A Gentle Introduction 3rd Edition, Britton & Doake, 2003, McGraw Hill (Essential reading) ISBN 0077099745

More Related