Presentation on theme: "44220: Database Design & Implementation ER Diagramming"— Presentation transcript:
144220: Database Design & Implementation ER Diagramming Ian PerryRoom: C41C Tel Ext.: 72871111
2Conceptual Data Modelling Process Identify ALL of the relevant Entities.must play a necessary role in the business system.Identify those Attributes that adequately describe each Entity.remember to choose ‘key’ attribute(s).Identify the Relationships between Entities.determine the Degree of each Relationship:determine the Type of each Relationship.attempt to decompose any many-to-many Relationships that you have identified.212022
3Hospital ExampleLet us suppose that you have been asked to build a Conceptual Data Model for a Hospital.The questions you must ask (and answer?) are as follows:What are the major objects of interest?EntitiesWhat details adequately describe each of these objects?AttributesWhat associations are valid between these objects?Relationships212022
4What are the Entities? i.e. the major objects of interest. Doctor NurseWardPatientMedicationOperationClinicetc.
5What are the Attributes? i.e. the details that adequately describe each of the Entities.WardName, Location, Number of Beds, …PatientName, Address, Date-of-Birth, Gender, …DoctorName, Room, Extension, Speciality, …NurseNB.Perhaps ‘people’ who work in the Hospital could be described using ONE Entity, i.e. Staff?
7‘Type’ of Relationships? i.e. associations which are valid, in BOTH directions, between pairs of Entities.Patient has Operation.Operation performed on PatientStaff work in WardWard employs StaffWard has beds for PatientPatient stays in WardPatient attends ClinicClinic treats PatientEtc.
8‘Degree’ of Relationships? One-to-One (1:1)Very rare!One-to-Many (1:M)Quite rare as a ‘real world’ relationship; however, what we require for both Logical and Physical Modelling.Many-to-Many (M:M)Most common as a ‘real world’ relationship; however, impossible to implement Logically or Physically.MUST be decomposed into two One-to-Many relationships linked by an ‘artificial’ Entity.131113
9Occurrence Diagrams? Staff Ward Use these (with values for Key Attributes) to discover how many occurrences of each Entity are actually on either side of a Relationship.StaffFred SmithJane BloggsArthur JonesAngela OustWardWard 1Ward 2Ward 3MM11
10Participation in a Relationship? Mandatory:compulsory attachment on both sides (very rare).Contingent:compulsion on one side only (most common).Optional:no compulsory attachment for either Entity (rare).Inclusive:attachment only occurs when another relationship exists (very rare).Exclusive:only one attachment from a set of possible relationships is permitted (quite rare).
11Degree, Type & Participation - 1 One-to-Many, Contingent (compulsion one side)WardPatienthas beds for =>1M<= stays inClinicPatienttreats =>1M<= attendsOne-to-Many, Contingent (compulsion one side)NB. a Patient can NOT both be staying in a Ward AND attending the Clinic, so these two Relationships are also Exclusive.2119
12Degree, Type & Participation - 2 Many-to-Many, Contingent (compulsion one side)PatientOperationhas =>M<= performed onStaffWardwork in =>M<= employsMany-to-Many, Contingent (compulsion one side)202018
13Decompose Complex Relationships StaffWardwork in =>M<= employsCan’t have any Many-to-Many Relationships; for example this one:MUST be decomposed into 2 x One-to-Many Relationships, linked by an ‘artificial’ Entity, i.e.:StaffWardTeamM1<= employswork in =>FirstNameFamilyNameWardNameWardNameFirstNameFamilyName201820
14Rules for Drawing ER Diagrams Need to look good:So, DON’T draw them by hand!Need to be well laid out, so that:Entities with several Relationships are in the centre of the diagram.AND related Entities are adjacent to each other.AND Relationship lines do not cross.
15The final Degree, Type & Participation Diags. WardPatienthas beds for =>1M<= stays inClinicPatienttreats =>1M<= attendsNB. the above Relationships are also Exclusive.StaffWardTeamM1<= employswork in =>PatientOperationPat/OpM1<= performed onhas =>i.e. having now ‘solved’ BOTH M:M Relationship ‘problems’.
16Plan BEFORE you begin!‘Patient’ has Relationships with THREE other Entities:so, place ‘Patient’ in centre of the Diagram.‘Ward’, ‘Team’ & ‘Pat/Op’ have Relationships with TWO other Entities:so, place these a little further out.The other 3 Entities (i.e. ‘Staff’, ‘Operation’ & ‘Clinic’ only have ONE Relationship:so, they should be placed on the outside of the digaram, close to the Entity that they have a Relationship with.Join all of the Entities:indicating the Degree, Type and Participation of each Relationship.
17ER Diagram for a Hospital PatientClinictreats =>1M<= attendsWardhas beds for =><= stays in#==========#OperationPat/Op<= performed onhas =>StaffTeam<= work in
18This Week’s WorkshopThe purpose of this week’s Workshop it to check that you can create good looking ER Diagrams, using a suitable software tool.If you haven’t already got a favourite drawing application I suggest you use PowerPoint.Your ER Diagrams MUST follow the diagram conventions given in this lecture.The same is true for Assignment 1.Part 1 - Draw Degree, Type & Participation diagrams, which:depict 4, relatively simple, ‘real-world’ situations.Part 2 - Begin working on Assignment 1, by:identifying the Entities from the Case Study.then, drawing Occurrence diagrams for each Pair of Entities.