Presentation is loading. Please wait.

Presentation is loading. Please wait.

Entity Relationship Modelling zDatabase Development zA Relational model zIts E-R equivalent zE-R notation zDeveloping an E-R Model zE-R difficulties.

Similar presentations


Presentation on theme: "Entity Relationship Modelling zDatabase Development zA Relational model zIts E-R equivalent zE-R notation zDeveloping an E-R Model zE-R difficulties."— Presentation transcript:

1 Entity Relationship Modelling zDatabase Development zA Relational model zIts E-R equivalent zE-R notation zDeveloping an E-R Model zE-R difficulties

2 Database Development zFrom UoD + requirement z To implemented system zHow to structure the activity? zDon’t do everything at once zSequence decisions - Users first, technology last zRelational model too close to technology

3 Why not Relational schema directly? zWhich DBMS will be used? yOracle - 7, 8, 9, Jet, MySQL? zMaybe another Data model altogether? yOLAP, Object oriented, Logical, XML zRelational schema too far from the user - ysome concepts are not user terms xe.g. primary keys, foreign keys ymany tables in schema are artifacts xe.g. resolving many-many relationships ysome relationships not explicit in schema x e.g. employee and salgrade, no self-managers

4 A Relational Schema zDept (Deptno, Dname, Loc) zEmp(Empno, ename, job, mgr, hiredate, sal, comm, deptno) zSalgrade(grade, losal, hisal) zOnly tables and columns, but columns used for different purposes - ywhat are they?

5 Different kinds of column zPrimary key - Underline zForeign Key - Italic zAttribute

6 zDept (Deptno, Dname, Loc) zEmp(Empno, ename, job, mgr, hiredate, sal, comm, deptno) zSalgrade(grade, losal, hisal)

7 zMore abstract - not specific to relational data model zEntity - cf- Table zRelation - cf Primary Key/Foreign key zAttribute - cf most columns zSometimes called an EAR model Entity Relation model

8 E-R <> Relational Schema zRelational Schema >>> E-R Model yWe will first use E-R models as a way to represent a Relational Schema, using the example database from the SQL workbook zUod >>> E-R model >>> Schema yWe will then use an E-R model as a step in translating user requirments into a database schema

9 E-R model of Employee DB zEntity: Department yAttributes: Name, Location zEntity: Employee yAttributes: Name, Job, Hiredate, MonthlySalary, Commission zEntity: SalaryGrade: yAttributes: Grade, losal, hisal zRelationship: yManages (Employee, set of Employee) zRelationship: yEmploys(Department,set of Employees)

10 E-R Diagrams zE-R models are often represented as diagrams. zDiagrams help to show Relationships clearly zNo single notation, so ensure you use a legend to explain your notation

11 E-R diagrams zEntity zRelationship z 1 to a set of (many) zAttribute Department name Employee

12 E-R instance diagram E1 E2E5E3 E4 D1 D2

13 Entity Questions zEntities are complex things of interest in the UoD zEntity corresponds to Table in Relational schema

14 Entities Department Employee SalaryGrade

15 Attribute questions zIs EmpNo an attribute yIf EmpNo already used in UoD, eg by an existing system, then it is an attribute yIf it is not of interest to the user, and just used to link tables, then ignore it

16 Attributes Department Name Location Employee Name Job AnnualSalary Commission Hiredate SalaryGrade Hisal Losal Grade

17 Employs relationship zMeaning - department currently employs - note that this changes over time zConstraints yevery employee must work for exactly one department ya department may employ zero, one or more employees yCardinality is 1 to 0.N

18 Relationships - Employs Department Name Location Employee Name Job AnnualSalary Commission Hiredate SalaryGrade Hisal Losal Grade employs

19 Manages relationship zEvery employee except the top guy has exactly one manager zEmployees manage zero, one or more employees zalso za manager cannot manage themselves - directly or indirectly

20 Relationship - Manages Department Name Location Employee Name Job AnnualSalary Commission Hiredate SalaryGrade Hisal Losal Grade employs manages

21 Relationship Employee-grade zIn the database this was ‘computed’ or ‘derived’ by finding the grade such that ylosal <= sal <= hisal zWe can show such relationships in E-R (but more common in an Object model)

22 Department Name Location Employee Name Job AnnualSalary Commission Hiredate SalaryGrade Hisal Losal Grade employs manages

23 From UoD to E-R model zWhich Entities? zEntity - Attribute - Relationship ambiguity zEntity or Instance of Entity zMany to Many relationships

24 Which Entities? z‘Nouns in description of Uod become entities in E-R’ zIs Job an entity zIs Location an entity zIs information required to be held about the term - details of responsibilities for Job, full address for Location.

25 Entity - Attribute - Relationship ambiguity zSuppose we need to know if an employee is married yAttribute - married - True/False yAttribute - name of spouse yRelationship - married to (another employee) yEntity - marriage, with date of marriage, date of divorce etc

26 Entity or Instance of Entity zEach Entity is a class of entity instances - yemployee entity has (14) entity instances zBook / Copy problem yBook has a title, author, ISBN yCopy has an accession no, location, condition, onloan Book Copy

27 Many to Many relationships zSuppose employees move between departments, so that over a period of time an employee is employed by several departments Department Employee employs

28 Department Employee Employment Hiredate Many to Many >> 2 One to Many

29 Next week zLecture :Normalization yChapter 23 zTutorial : E-R modelling exercises


Download ppt "Entity Relationship Modelling zDatabase Development zA Relational model zIts E-R equivalent zE-R notation zDeveloping an E-R Model zE-R difficulties."

Similar presentations


Ads by Google