Upload
ahmerjamil
View
48
Download
4
Embed Size (px)
Citation preview
© Louis D. Nel 1996-2003 102 ER ModelingCOMP 3005 Databases
Module 2
Modeling Data
© Louis D. Nel 1996-2003 202 ER ModelingCOMP 3005 Databases
Object-Oriented Concepts
• Learn the Entity-Relationship approach to modelling data
• Reference: Elmasri & Navathe, 2nd edition chapter 3
Objectives
© Louis D. Nel 1996-2003 302 ER ModelingCOMP 3005 Databases
Object-Oriented Concepts
Topics
• Introduction to E-R model and notation• Example E-R model constructs
© Louis D. Nel 1996-2003 402 ER ModelingCOMP 3005 Databases
Modelling Data
RequirementsCapture
Analysis
ConceptualData Modeling
Customer
(Activity) (Work Product)
Application Requirements
Description ofData Requirements
Enterprise DataModel
© Louis D. Nel 1996-2003 502 ER ModelingCOMP 3005 Databases
Scenarios
• A company wishes to store and access information about its employees, departments and projects.
• Departments will want to generate various reports from the stored data
© Louis D. Nel 1996-2003 602 ER ModelingCOMP 3005 Databases
e.g. Data Description (3.2)
• Company organized into department which have unique name, unique number, manager and date manager started.
• A Department has many locations and controls projects• Each project has a name and unique location• Employee information includes: name, sin number, address,
salary, sex, and birth date. An employee works for one department, but may work on several projects (which could be from different departments)
• Employees have a supervisor and we want to keep track of the number of hours per week they spend on each project
• For insurance purposes the company keeps track of an employees depends. It records the dependents name, sex, birthdate, and relationship to the employee
© Louis D. Nel 1996-2003 702 ER ModelingCOMP 3005 Databases
E-R diagram for Company Data (fig 3.2)
Employee
Dependent
1
1
11
N
N
NM1 N
1
N
Supervisor Supervisee
Bdate
Sin
Name
Sex AddressSalary
Name
NoLocation
StartDate
Supervision
Dependentsof
ManagesDepartment
Location
WorksFor
Project
Controls
Name
No
WorksOn
BdateName Sex Relationship
hours
© Louis D. Nel 1996-2003 802 ER ModelingCOMP 3005 Databases
Entity-Relationship Notation
Manages
Employee Address
Name
Location
Name
Entity
Dependent Weak Entity
Relationship
IdentifyingRelationship(for weak entities)
Attribute
Key Attribute
Discriminator “weak key”
Total participation of E2in R. (E2 can only exist ifit participates in R)
Cardinality 1:N for E1:E2
1 N (min,max)
E must participatein at least min and at most max associations in R
Address Derived Attribute
Multi-valued Attribute
Dependentsof
E1 R E2 E1 R E2 R E
© Louis D. Nel 1996-2003 902 ER ModelingCOMP 3005 Databases
Entities and Attributes
Person
Address
SINDegrees
Entity:a thing with independent existencee.g. person, company, course, job ...
Entity describes a Typevalues are called Entity Sets, orExtensions
Age
Person
Birth Date
Number Street City
First Last
Address
Attribute:Properties of entities, the things whichactually hold the values
Attributes an be assigned null value
Name
© Louis D. Nel 1996-2003 1002 ER ModelingCOMP 3005 Databases
Key Attributes
Address
SIN
Key: Attributes whose values can distinguish different entities(No two entity set elements can agree in their key attributes
Person
Number Street CityFirst Last
Name
Some data models require keys, e.g. relational modelother may not e.g. object-oriented model
Name_Address
Key attributes areunderlined inE-R model
© Louis D. Nel 1996-2003 1102 ER ModelingCOMP 3005 Databases
Syntactic Description of Entities and Attributes
Address
SINDegrees
Age
Person
Birth Date
Number Street City
First Last
PERSONSIN,Name(First_Name,Last_Name),Address(Number,Street,City),Birth_Date,{Degrees}
( ) = composite attribute{ } = multi-values attribute
Name
© Louis D. Nel 1996-2003 1202 ER ModelingCOMP 3005 Databases
Attribute Values and Domains
E
E = EntityA = AttributeA(e) = value of attribute A
of entity type e
V = value set of A in E(Domain of A)
P(V) = powerset of V
A: E -> P(V)
A
Person
E = PersonA = DegreesA(e) = {Bsc, Msc}
V = {Bsc, Msc, PhD}
P(V) = { {} {Bsc} {Msc} {PhD}{Bsc, Msc} {Msc, PhD} {Bsc, PhD}{Bsc, Msc, PhD} }
A(e) ∈ P(V)
Example
Degrees
© Louis D. Nel 1996-2003 1302 ER ModelingCOMP 3005 Databases
Initial Entities for Company Database (fig 3.8)
Employee
Bdate
Sin
Name
Sex Address Salary
Name
NoLocation
Manager
Location
Project
Name
No
BdateName Sex
Relationship
Manager Start Date
EmployeeDependent
Department
EmployeeName,SIN,Sex,Address,SalaryBdate,Department,Supervisor,WorksOn{Project, Hours}
Department
Supervisor
WorksOn
Department
DepartmentName,No,{Location}Manager, ManagerStartDate
DependentName,Sex,Bdate,EmployeeRelationship
ProjectName,No,Location,Department
© Louis D. Nel 1996-2003 1402 ER ModelingCOMP 3005 Databases
E-R diagram for Company Data (fig 3.2)
Employee
Dependent
1
1
11
N
N
NM1 N
1
N
Supervisor Supervisee
Bdate
Sin
Name
Sex AddressSalary
Name
NoLocation
StartDate
Supervision
Dependentsof
ManagesDepartment
Location
WorksFor
Project
Controls
Name
No
WorksOn
BdateName Sex Relationship
hours
© Louis D. Nel 1996-2003 1502 ER ModelingCOMP 3005 Databases
Constraints on Relationship Cardinalities
One to One Many to One
One to Many Many to Many
© Louis D. Nel 1996-2003 1602 ER ModelingCOMP 3005 Databases
Employee 11Department
Example Relationships with Constraints
Manages
Employee 1NDepartmentWorks For
Employee MNProjectWorks On
Employee
N
Supervises
1Supervisor
Supervisee
© Louis D. Nel 1996-2003 1702 ER ModelingCOMP 3005 Databases
Employee MNProject
Relationships can have attributes
Works On
Number Hours
Employee 11DepartmentManages
StartDate StartDateStartDate
Employee 1NDepartmentWorks For
StartDateStartDate
© Louis D. Nel 1996-2003 1802 ER ModelingCOMP 3005 Databases
Employee
Dependent
Dependentsof
Weak Entities
Identifying Entity (owner)Employeename,SIN,address...
Identifying RelationshipEmployeename,SIN,address...
Weak EntityDependentname,age,relationship
has descriminator or partial key
totalparticipationmandatory
In simple cases weak entities can be handled as multivaluedattributes of the owner entity
© Louis D. Nel 1996-2003 1902 ER ModelingCOMP 3005 Databases
Company E-R diagram Alternative Notation (fig 3.14)
Employee
Dependent
SupervisorSupervisee
Bdate
Sin
Name
Sex AddressSalary Name
NoLocation
StartDate
Supervision
Dependentsof
ManagesDepartment
Location
WorksFor
Project
Controls
Name
No
WorksOn
BdateName Sex Relationship
hours
(0,1) (1,1)
(1,1)(4,N)
(1,N)
(1,N)
(0,N)
(1,1)(0,N)
(1,1)
(0,1)(0,N)
manageddept.
manager
© Louis D. Nel 1996-2003 2002 ER ModelingCOMP 3005 Databases
Supplier Project
Higher Order Relationships
Supply
Part
Quantity ProjNameSupName
PartNo
Supplier ProjectSupplies
Part
StartDateProjNameSupName
PartNoNeedsCanSupply
M N
M
N
M
N
© Louis D. Nel 1996-2003 2102 ER ModelingCOMP 3005 Databases
Supplier Project
Equivalent Binary Relationship
Supply
Part
Quantity ProjNameSupName
PartNo
NSupplySS SPj
SPt
Supplier Project
Part
SupName Quantity ProjName
PartNo
N
N
1 1
1
© Louis D. Nel 1996-2003 2202 ER ModelingCOMP 3005 Databases
Vehicle
Inheritance
VIN
Car Bicycle
Frame sizeEngine size
Is a
Colour
owner
Number of doors
Component group