D I T211 Chapter 3


Published on

Published in: Technology, Business
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

D I T211 Chapter 3

  1. 1. Chapter 3 Entity Relationship Modelling
  2. 2. Objectives <ul><li>At the end of this chapter, students should be able to: </li></ul><ul><li>Understand the basic concept of Entity Relationship (ER) model that consists of elements and notation. </li></ul><ul><li>Identify entities, attributes and attribute-types. </li></ul><ul><li>Identify the relationship and cardinality constraint. </li></ul><ul><li>Identify the relation key and integrity constraint. </li></ul><ul><li>Define Entity Relationship (ER) Diagram. </li></ul><ul><li>Create an ER diagram using the step by step approach. </li></ul>
  3. 3. Introduction <ul><li>Entity Relationship (ER) diagram is a graphical diagram used at the design stage of database system’s development for gathering data. </li></ul><ul><li>ER diagram consists of three elements, which are entities , attributes and relationship , and they are each associated to a notation or symbol for constructing a meaningful ER diagram. </li></ul><ul><li>Entity Relationship Modeling is a process used to help us to understand and document the informational requirements of a system. </li></ul><ul><li>A database system is normally built according to three major stages: </li></ul><ul><ul><li>1. requirements </li></ul></ul><ul><ul><li>2. design </li></ul></ul><ul><ul><li>3. implementation </li></ul></ul>
  4. 4. ER Model & ER Diagram <ul><li>The Entity Relation model is presented using the ER diagram. </li></ul><ul><li>Entity relationship diagram is a graphical diagram that depicts entity relationship model that comprises entities, attributes and relationship . It also displays connectivity and cardinality . </li></ul>
  5. 5. Elements of ER Model <ul><li>There are 3 elements of ER Model: </li></ul><ul><li>Entities </li></ul><ul><li>Attributes (which include: simple, multivalue, composite, derived) </li></ul><ul><li>Relationship </li></ul>
  6. 6. Elements of ER Model (cont.) <ul><li>ENTITY </li></ul><ul><ul><li>Definition </li></ul></ul><ul><ul><ul><li>Entity is a person, place, object, event or concept, which you want to store the information in a table. </li></ul></ul></ul><ul><ul><li>Characteristics of an entity </li></ul></ul><ul><ul><ul><li>Must have a set of attributes </li></ul></ul></ul><ul><ul><ul><li>Will become a table in a database </li></ul></ul></ul><ul><ul><li>Examples of entity </li></ul></ul>
  7. 7. Elements of ER Model (cont.) <ul><li>ENTITY </li></ul><ul><ul><li>What is entity type? </li></ul></ul><ul><ul><ul><li>A collection of entities that shares the same characteristics. </li></ul></ul></ul><ul><ul><li>What is entity instance? </li></ul></ul><ul><ul><ul><li>Data for entity types. </li></ul></ul></ul><ul><ul><li>Example of entity type and entity instance </li></ul></ul>
  8. 8. Elements of ER Model (cont.) <ul><li>ATTRIBUTE </li></ul><ul><ul><li>Definition </li></ul></ul><ul><ul><ul><li>Attributes are the characteristics of an entity or objects </li></ul></ul></ul><ul><ul><ul><li>Attribute has a name and data type. </li></ul></ul></ul>
  9. 9. Elements of ER Model (cont.)
  10. 10. Elements of ER Model (cont.) <ul><li>ATTRIBUTE </li></ul><ul><ul><li>Example </li></ul></ul>
  11. 11. Elements of ER Model (cont.) <ul><li>RELATIONSHIP </li></ul><ul><li>A relationship, which is an association between entities, is defined by a diamond shaped symbol in an ER diagram. </li></ul><ul><li>The relationship that is depicted by a diamond is labelled with verb or verb phrase. </li></ul>
  12. 12. Cardinality Constraint <ul><li>Definition: The number of entity type, which is involved in a relationship. </li></ul><ul><li>Types of cardinality constraints </li></ul><ul><li>a) One to One Relationship (1:1) </li></ul><ul><ul><li>Definition : Maximum one X for each Y and 1 Y for each X. </li></ul></ul>Primary key
  13. 13. Cardinality Constraint (cont.) <ul><li>b) One to Many Relationship (1:M) </li></ul><ul><ul><li>Definition: Maximum one X for each Y and possibly many Y’s for each X. </li></ul></ul>Primary key Foreign key
  14. 14. Cardinality Constraint (cont.) <ul><li>c) Many to One Relationship (M:1) </li></ul><ul><ul><li>Definition: Possibly many X’s for each Y and maximum one Y for each X. </li></ul></ul>Primary key Foreign key
  15. 15. Cardinality Constraint (cont.) <ul><li>d) Many to Many Relationship (M:N) </li></ul><ul><ul><li>Definition: Possibly many X’s for each Y and many Y’s for each X. </li></ul></ul>Composite entity Composite keys
  16. 16. E R Diagram <ul><li>Example 1 </li></ul>
  17. 17. E R Diagram (cont.)
  18. 18. E R Diagram (cont.) <ul><li>Example 2 </li></ul>
  19. 19. E R Diagram (cont.)
  20. 20. Relational Key <ul><li>Relational Key Definition </li></ul><ul><ul><li>A key consists of one or more attributes that can be identified in a row. </li></ul></ul><ul><ul><li>Relational key is an attribute that relates one entity with another entity in a relationship. </li></ul></ul><ul><li>Why we need Relational Key? </li></ul><ul><ul><li>Relational key enables us to link the tables together in a database for easier data access storage. </li></ul></ul>
  21. 21. Relational Keys (cont.) <ul><li>Types of Relational Keys </li></ul>
  22. 23. Integrity Rules <ul><li>Two types of integrity constraint are Entity Integrity and Referential Integrity . </li></ul><ul><li>a) Entity Integrity </li></ul><ul><ul><li>Requirement: </li></ul></ul><ul><ul><ul><li>All entries are unique and no part of a primary key may be null. </li></ul></ul></ul><ul><ul><li>Purpose: </li></ul></ul><ul><ul><ul><li>Guarantees that each entity will have a unique identity and ensures that foreign key values can properly refer to primary key values. </li></ul></ul></ul>
  23. 24. Integrity Rules (cont.) <ul><li>b) Referential Integrity </li></ul><ul><ul><li>Referential integrity is a set of rules that prevents you from changing or deleting a record if matching records exist in a related table. </li></ul></ul><ul><ul><li>Requirement : </li></ul></ul><ul><ul><ul><li>If foreign key exist in one table then the foreign key value must reference an existing primary key value in a table to which it is related and it can be null. </li></ul></ul></ul><ul><ul><li>Purpose : </li></ul></ul><ul><ul><ul><li>Possibility for non-corresponding value, but impossible for invalid entity. </li></ul></ul></ul><ul><ul><ul><li>Referential integrity rule disables row deletion of a table consisting primary key matching key values in another table. </li></ul></ul></ul>
  24. 26. Steps to Develop ERD
  25. 27. Examples <ul><li>Example 1 </li></ul><ul><li>A company has several departments. Each department has a supervisor and at least one employee. Employees must be assigned to at least one department. Project will be given to the employee and it will be done in a group. At least one employee is assigned to one project or more. The important data fields are the names of the departments, projects, supervisors and employees, as well as the supervisor and employee number, department code and a unique project number. </li></ul>
  26. 28. Examples (cont.) <ul><li>Example 2 </li></ul><ul><li>Create an ER diagram for the following requirements with the appropriate attributes for each entity type and structural constraints for each relationship type. </li></ul><ul><ul><li>An INVOICE is written by a SALESREP. Each sales representative can write many invoices, but each invoice is written by a single sales representative. </li></ul></ul><ul><ul><li>(b) The INVOICE is written for a single CUSTOMER. However, each customer can have many invoices. </li></ul></ul><ul><ul><li>(c) An INVOICE can include many details (DETAIL-LINES), which describe the products bought by the customer. </li></ul></ul><ul><ul><li>(d) The product information is stored in a PRODUCT entity. </li></ul></ul>
  27. 29. Examples (cont.) <ul><li>Example 3 </li></ul><ul><li>You have been requested by a travel agency, EXEL Travels, to build a database for storing information on customers and vacation package that have been booked. Create an ER Diagram based on the information below: </li></ul><ul><ul><li>Each customer has information like Customer Number, Name, Address and Telephone number. </li></ul></ul><ul><ul><li>Customers may have many addresses and telephone numbers. </li></ul></ul><ul><ul><li>A customer may book more than one holiday package and one holiday package may also be booked by many customers. </li></ul></ul><ul><ul><li>Examples of payments according to booked holiday package : </li></ul></ul><ul><ul><ul><li>Package A : New Zealand (3 days) - RM 3500 </li></ul></ul></ul><ul><ul><ul><li>Package B : New Zealand (7 days) - RM 5000 </li></ul></ul></ul><ul><ul><ul><li>Package C : New Zealand (10 days) - RM5990 </li></ul></ul></ul>
  28. 30. Examples (cont.) <ul><li>Example 4 </li></ul><ul><li>Hospital Jaya is based in Kuala Lumpur. This Hospital has a few wards with several patients. This ward has a few types, which depends on types of patients. </li></ul><ul><li>Patients will be recorded into file that have ID Patient, Patient name, address, phone number, IC-number, categories either VIP or regular patient and a group of blood patient. Each patient is treated by a doctor at one time but one doctor can treats a number of patients. </li></ul><ul><li>The information of doctors recorded is: Doctor ID, name, address, phone number, IC-number and specialization. </li></ul><ul><li>The nurses will be assigned to take care of the patients. Nurses in this hospital are graded based on their experience, qualification and duration of working in the hospital. </li></ul>
  29. 31. Examples (cont.) <ul><li>Example 5 </li></ul>