Entity-Relationship Modelling Introduced by Chen in 1976 The ER Model is used to construct the conceptual data model – independent of DBMS Most widely used techniques for modelling of business domains data requirements
Entity-Relationship Modelling R K Bhagat
Entity A ‘thing’ which can be distinctly identified A distinguishable object from the problem domain e.g. –STUDENT, UNIT, COURSE –EMPLOYEE, DEPARTMENT, COMPANY Real or abstract –Book, Author –Loan, Sale
Choosing Entities Usually ‘nouns’ from the problem domain – CUSTOMER, ORDER, SUPPLIER – AIRCRAFT, SEAT, FLIGHT, AIRLINE – Eliminate synonyms AIRCRAFT and PLANE are the same entity –Beware of roles that should be entities, e.g - MACHINIST should be EMPLOYEE DELIVERY VAN should be VEHICLE
Drawing Entities Entities are in UPPER CASE and singular - ‘EMPLOYEE’ not ‘employees’ Each entity instance must be uniquely identified by a primary key national_insurance_number EMPLOYEE
Attributes Attributes are details that identify, quantify or describe the entity Attributes take values from a domain e.g. month = {Jan, Feb, Mar, …. Dec} unit = {DBS1, BP, BITS1, ICT, ACC} Ensure that the attribute really describes the entity, e.g. shirt_colour is an attribute of TEAM, not PLAYER
Drawing Attributes Attributes appear below the entity that they describe in lower case Use underlining to denote the primary key department_number name location DEPARTMENT
Primary Key The primary key is the attribute, or set of attributes, that uniquely identifies all of the entity instances Ensure that the primary key uniquely identifies the instances, e.g – ‘student_id’ is unique, but ‘surname’ is not There are other types of key – foreign, composite, candidate
Relationships ‘An association among entities’ A named significant association A binary association that links two entities Drawn as the line on the diagram Cardinality –one to one –one to many –many to many
One-to-One Relationship A HUSBAND has one WIFE A WIFE has one HUSBAND
One-to-Many Relationship A DEPARTMENT has one or more EMPLOYEEs
Many-to-Many Relationship A STUDENT attends one or more UNITs A UNIT is taken by one or more STUDENTs
Checking for Redundant Relationships
Steps in Entity Relationship Modelling 1. Identify the entities. 2. Identify the relationships using a relationship grid. 3. Identify the relationship types 4. Draw the entity-relationship diagram. 5. Check for and remove redundant relationships
Steps in Entity Relationship Modelling 6. Remove many-to-many relationships. 7. Identify/create the primary key for each entity 8. Convert one-to-many relationships to foreign keys. 9. Identify/create additional attributes for each entity. 10. Define the relations corresponding to the entity- relationship model. 11. Create the relations in the Database Management System 12. Declare the primary keys and foreign keys.
The Scenario ‘CD-Direct’ is a new Internet Retailer that sells Compact Discs using the web. They require a relational database to store details of the orders placed by their customers. A customer can make one or more orders. For each order, an employee picks out the compact disc and sends them to the customer who placed the order. More than one disc can be ordered on the same order. The company requires that information about which employee dealt with each order be recorded in the database for management reasons. An invoice is sent to the customer with the ordered goods.
Check for and remove redundant relationships
Summary Identify the entities Identify relationships between entities Remove any redundant relationships Remove M:N relationships by adding an extra entity – many go on the extra entity Add primary keys and foreign keys –foreign keys are the primary keys from the one put into the many side of the relationship Add additional attributes Convert into a set of relations