1 / 25

Data Modelling – ERD Entity Relationship Diagram’s

Data Modelling – ERD Entity Relationship Diagram’s. Entity Relationship Diagrams and how to create them. What is an Entity Relationship Diagram?. Drawing technique used to analyse the logical structure of an organisations information (e.g. database).

geona
Télécharger la présentation

Data Modelling – ERD Entity Relationship Diagram’s

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. Data Modelling – ERDEntity Relationship Diagram’s Entity Relationship Diagrams and how to create them.

  2. What is an Entity Relationship Diagram? • Drawing technique used to analyse the logical structure of an organisations information (e.g. database). • An entity is an object or concept about which the system needs to hold information eg .............................................. • Each entity must be involved in at least one relationship, and may be involved in more than one relationship.

  3. Relationships • What information will be kept in the system? The entities and their attributes. • Egof attributes ............................................. • For example, how do we represent a relationship between a book copy and a borrower in a library? Do we wish to say: • “A book copy may be borrowed by only one borrower” or • “A book copy may be borrowed by one or more borrowers” ?

  4. Entity Relationship Diagram’s • Pairs of entities are linked. • All entities in the system relate directly or indirectly with all the others. • How many relationships may exist between linked entities? • This consideration is called multiplicity or cardinality.

  5. Types of Relationships There are three ways that entities can be linked together: • One-to-one • One-to-many • Many-to-many

  6. One-to-One Relationship • One occurrence of an entity ‘A’ is related to one and only one occurrence of the entity ‘B’ and • One occurrence of an entity ‘B’ is related to one and only one occurrence of the entity ‘A’

  7. One-to-One continued • There are two link phrases used on the relationship. • Use the phrase ‘one and only one’ rather than ‘one’ to emphasise the cardinality existing at the both ends of this relationship. • Consider joining the two entities. • We might have one entity called School that would include all the attributes of the Head Teacher. • This would have the advantage of reducing the number of entities. • But it might make the model produced less clear.

  8. One-to-Many Relationship • One occurrence of an entity ‘A’ is linked to one or more occurrences of another entity ‘B’ and • One occurrence of entity ‘B’ is linked to one and only one occurrence of entity ‘A’

  9. Many-to-Many Relationships • One occurrence of an entity ‘A’ is linked to one or more occurrences of another entity ‘B’ and • One occurrence of entity ‘B’ is linked to one or more occurrences of entity ‘A’

  10. Deciding on Relationships • Which pairs of entities have a direct relationship? • Looking out for verbs – ‘A stockholder of the company owns shares in that company’ • Sometimes we might not want to include a direct relationship between two entities because an indirect relationship already exists - ‘Customer buys Products’ • We may already have - ‘Customer places Order’ and ‘Order lists Products’

  11. The Problem with Many-to-Many

  12. The Problem with Many-to-Many • Project Code is included in the engineer table to provide a link between the two. • What happens if an engineer works on two projects at the same time? We would need more than one value in the Project Code? (engineer ID51 works on both project W45 and Y65). • Solution: form another table which links the two tables together.

  13. Solving Many-to-Many • Any engineer may be linked via an assignment table to a number of projects. • Any project may have more than one engineer working on it. • We need a link entity. • Sometimes the name of this link entity is difficult to work out.

  14. The Solution • We now have 2 one-to-many relationships instead of 1 many-to-many relationship.

  15. Mandatory and Optional Relationships In this case we interpret the relationship as: • A School employs one or more Teachers. • A Teacher is employed at one and only one School.

  16. Mandatory and Optional Relationships • Suppose some teachers are employed in more than one school - they may move around within an area and visit a number of schools. • It is possible, that a teacher is not currently employed - that particular teacher would not participate in this relationship.

  17. Mandatory and Optional Syntax A [name of entity] may / must ‘link phrase’ (one and only one) / (one or more) [name of entity] A School must employ many Teachers. A Teacher may be employed in one School.

  18. Referential Integrity • We insist on the mandatory part of the relationship between Order and Customer. • We do not want an Order created which is not related to a particular Customer. • This is known as referential integrity. • All databases support this structure.

  19. Referential Integrity • When a user enters a new order it must relate to an existing customer. • We cannot delete a customer for which there are existing orders. • We can enter a customer without requiring an order to be related to that customer.

  20. Attributes and Primary Keys • You will assigned data types to attributes. • You must created primary keys for tables. • You can then link tables together.

  21. Foreign Keys • An Order may not be produced which is not related to an existing customer. Therefore, every time we enter a new order we must identify an existing Customer ID, so Customer ID would be a field on the Order table. • This is called a Foreign key as Customer ID is a primary key on the Customer table. • Foreign keys are identified by an asterisk * • If we relaxed this condition and did not insist on referential integrity we would be allowed to enter no-value for this foreign key. • Wherever possible we will endeavour to use referential integrity.

  22. Entity Attribute Relationship Model • Select the entities. • Identify relationships between entities (including decisions about mandatory and optional relationships). • Resolve any many-to-many relationships. • List the entities with their attributes. • Identify suitable primary keys. • Place the required foreign keys in the detail entities.

  23. Example – Steps 1 to 3 • Select the entities. • Populate the entities with attributes. • Identify suitable primary keys.

  24. Example – Steps 4 to 6 • Identify relationships between entities. • Resolve any many-to-many relationships. • Place the required foreign keys in the detail entities.

  25. Things to Note • Course ID is a foreign key on Course Offering table and Course ID is used as part of the primary key. • Employee Number is used as a foreign key on the Booking table. • Other foreign keys need to be included. • It is now possible to answer questions such as: • Who made this Booking? • Which Course Offering is this booking for? • Which Courses is a Staff Member booked to study?

More Related