Entity Relationship Modelling zDatabase Development zA Relational model zIts E-R equivalent zE-R...
-
date post
20-Dec-2015 -
Category
Documents
-
view
215 -
download
0
Transcript of Entity Relationship Modelling zDatabase Development zA Relational model zIts E-R equivalent zE-R...
Entity Relationship Modelling
Database Development A Relational modelIts E-R equivalentE-R notationDeveloping an E-R ModelE-R difficulties
Database Development
From UoD + requirement To implemented systemHow to structure the activity?Don’t do everything at onceSequence decisions - Users first,
technology lastRelational model too close to
technology
Why not Relational schema directly?
Which DBMS will be used? Oracle - 7, 8, 9, Jet, MySQL?
Maybe another Data model altogether? OLAP, Object oriented, Logical, XML
Relational schema too far from the user - some concepts are not user terms
e.g. primary keys, foreign keys
many tables in schema are artifactse.g. resolving many-many relationships
some relationships not explicit in schema e.g. employee and salgrade, no self-managers
A Relational Schema
Dept (Deptno, Dname, Loc)Emp(Empno, ename, job, mgr,
hiredate, sal, comm, deptno)Salgrade(grade, losal, hisal)
Only tables and columns, but columns used for different purposes - what are they?
Dept (Deptno, Dname, Loc)Emp(Empno, ename, job, mgr,
hiredate, sal, comm, deptno)Salgrade(grade, losal, hisal)
More abstract - not specific to relational data model
Entity - cf- TableRelation - cf Primary Key/Foreign keyAttribute - cf most columns
Sometimes called an EAR model
Entity Relation model
E-R <> Relational Schema
Relational Schema >>> E-R Model We will first use E-R models as a way to
represent a Relational Schema, using the example database from the SQL workbook
Uod >>> E-R model >>> Schema We will then use an E-R model as a step
in translating user requirments into a database schema
E-R model of Employee DBEntity: Department
Attributes: Name, LocationEntity: Employee
Attributes: Name, Job, Hiredate, MonthlySalary, Commission
Entity: SalaryGrade: Attributes: Grade, losal, hisal
Relationship: Manages (Employee, set of Employee)
Relationship: Employs(Department,set of Employees)
E-R Diagrams
E-R models are often represented as diagrams.
Diagrams help to show Relationships clearly
No single notation, so ensure you use a legend to explain your notation
Entity Questions
Entities are complex things of interest in the UoD
Entity corresponds to Table in Relational schema
Attribute questions
Is EmpNo an attribute If EmpNo already used in UoD, eg by an
existing system, then it is an attribute If it is not of interest to the user, and
just used to link tables, then ignore it
Attributes
DepartmentName
Location
EmployeeName
Job
AnnualSalary Commission
Hiredate
SalaryGrade
Hisal
Losal
Grade
Employs relationship
Meaning - department currently employs - note that this changes over time
Constraints every employee must work for exactly one
department a department may employ zero, one or
more employees Cardinality is 1 to 0.N
Relationships - Employs
DepartmentName
Location
EmployeeName
Job
AnnualSalary Commission
Hiredate
SalaryGrade
Hisal
Losal
Grade
employs
Manages relationship
Every employee except the top guy has exactly one manager
Employees manage zero, one or more employees
alsoa manager cannot manage
themselves - directly or indirectly
Relationship - Manages
DepartmentName
Location
EmployeeName
Job
AnnualSalary Commission
Hiredate
SalaryGrade
Hisal
Losal
Grade
employsmanages
Relationship Employee-grade
In the database this was ‘computed’ or ‘derived’ by finding the grade such that losal <= sal <= hisal
We can show such relationships in E-R (but more common in an Object model)
DepartmentName
Location
EmployeeName
Job
AnnualSalary Commission
Hiredate
SalaryGrade
Hisal
Losal
Grade
employsmanages
From UoD to E-R model
Which Entities?Entity - Attribute - Relationship
ambiguityEntity or Instance of EntityMany to Many relationships
Which Entities?
‘Nouns in description of Uod become entities in E-R’
Is Job an entityIs Location an entityIs information required to be held
about the term - details of responsibilities for Job, full address for Location.
Entity - Attribute - Relationship ambiguity
Suppose we need to know if an employee is married Attribute - married - True/False Attribute - name of spouse Relationship - married to (another
employee) Entity - marriage, with date of marriage,
date of divorce etc
Entity or Instance of Entity
Each Entity is a class of entity instances - employee entity has (14) entity
instancesBook / Copy problem
Book has a title, author, ISBN Copy has an accession no, location,
condition, onloanBook Copy
Many to Many relationships
Suppose employees move between departments, so that over a period of time an employee is employed by several departments
Department
Employee
employs