270 likes | 289 Views
CS 4310: Software Engineering. Lecture 5 Entity Relationship Modelling. Entity-Relationship Model. Technique for carrying out the conceptual and logical design of the system A widely accepted data modelling approach 3 basic notions: entities attributes relationships.
E N D
CS 4310: Software Engineering Lecture 5 Entity Relationship Modelling
Entity-Relationship Model • Technique for carrying out the conceptual and logical design of the system • A widely accepted data modelling approach • 3 basic notions: • entities • attributes • relationships
What is an entity? • An entity is an object that can be identified in the users’ work environment and that users want to track.
Entities • An entity is a thing or object in the real world (within the application context) • An entity has a set of properties which uniquely identify it. • An entity is represented as a rectangle in an ER diagram Project
What is an Attribute? • An attribute describes a characteristic of an entity • For example: • An entity: Employee • Has attributes: • Employee_Name • Extension • Date_Of_Hire
Attributes • Example: Project = (proj_name, location, budget, • start_date, end_date) • Represented as ellipses in an ER diagram budget start_date location Project end_date proj_name
What are Relationships? • Relationships are associations between entities which express some real world relationship Project Employs Employee • Project and Employeeparticipate in the employs relationship • The function that an entity plays in a relationship is called that entity’s role
Relationship Sets starts at • There can be more than one relationship between entities. • There can be recursive relationships that can indicate roles for clarity. • A relationship can also have descriptive attributes. Road Town ends at manager works for Employee worker date Client orders Book
Degree of Relationships • Refers to the number of entities participating in a relationship • Most relationships are binary (degree 2), but can also have ternary (degree 3) relationships. Name proj_name Hires Project Contractor location Address budget end_date start_date end_date Contract number start_date value
Mapping Cardinalities • Express the number of entities to which another entity can be associated via a relationship • For a binary relationship, the mapping cardinality can be one of the following: • one to one • one to many • many to one • many to many
Cardinality Examples Person ID Book • A person has only one ID book and an ID book belongs to only 1 person • A person can own many cars (possibly 0), but a car only has 1 owner • A person can own many houses and a house can have multiple owners owns Person Car owns Person House owns
Design Issues • Entity or Attribute? • Example: should location be an entity or an attribute? • can a project be in more than 1 location? • Entity or Relationship? • generally: relationships for actions between entities • whatever “makes sense” in application context
ER Diagram Symbols Entity Set One-to-one link Many-to-one link Attribute Many-to-many link Relationship
Example ERD start_date budget ID surname end_date first_name proj_name employs Project Employee location position year_joined start_date end_date eliminates year_left species Alien area
ER Design: Where to Start • Identify entity sets • Describe the entity sets with attributes • Specify relationships and cardinalities
Simple Modelling Example • Every department within the company is in only one division. • Each division has more than one department in it. • There is no upper limit on the number of departments that a division can have.
1. Define Entities Division Department Employee
2. Define Relationships Division contains Department manages Employee
3. Define Cardinality Division contains Department manages Employee
is sent by Standard Notation A plain rectangle is used to represent the entity type. INVOICE A labeled line to represent the relationship. 1 : 1 A B A B 1 : N
Diagram with Standard Notation Division contains Department manages Employee
has enrolled COURSE STUDENT refers to LOAN BOOK Notation Examples ONE course has enrolled ONE or MORE students. ONE student is enrolled on ONE course. ONE loan refers to ONE book. ONE book is referred to ONE loan.
supplies SUPPLIER PART Many-to-Many Relationship Example • Any one supplier might supply more than one kind of part. • Any one kind of part might be bought from a number of different suppliers.
More Examples is associated Property Customer can place Order Customer teach Students Teachers
Example - Simple Hospital System WARD DOCTOR has accommodates treats assigned AILMENT NURSE PATIENT cares for suffers from
College System DEPARTMENT is_in offers COURSE LECTURER teaches enrols STUDENT
Your Project Work • Develop Requirements Document. • Think about your system’s entities and relationships