1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of...
-
Upload
hector-knight -
Category
Documents
-
view
222 -
download
2
Transcript of 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of...
![Page 1: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/1.jpg)
1
More on ER Model Detail Relationships
4
![Page 2: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/2.jpg)
2
Attributes
Attribute A property or characteristic of an entity type
that is of interest to the organisation Simple Attribute
An attribute that cannot be broken down into smaller components
e.g. Emp No
Emp No
Detail Conceptual Data Model
![Page 3: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/3.jpg)
3
Multi-valued Attribute An attribute that may take on more than one
value for a given entity instancee.g. Employee Skills, Qualifications
Attributes Cont’d
Composite Attribute An attribute that can be broken down into
component parts
e.g. Address (Street, City, State, Postal Code) Name (First Name, Middle Initials, Last
Name)
Skills
Name
First Name
Mid Initials
Last Name
![Page 4: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/4.jpg)
4
Attributes Cont’d
Stored Attribute An attribute whose valued is stored in the
database Derived Attribute
An attribute whose values can be calculated from related attribute values
e.g. Years Employed (using Employed Date) Age (using Date of Birth)
Age
![Page 5: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/5.jpg)
5
Identifier
Composite Identifier An identifier that consists of a composite
attributee.g. Flight Id (Flight No, Date)
Employee Emp No
Flight Flight Id
Flight No
Date
Identifier An attribute (or combination of attributes)
that uniquely identifiers individual instances of an entity type
e.g. Emp No
![Page 6: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/6.jpg)
6
Identifier Choose an identifier that will not change its
value over the life of each instance of the entity type
Choose an identifier such that each instance of the entity type, the attribute is guaranteed to have valid values and not be null (or unknown)
Avoid the use of so-called intelligent identifiers, whose structure indicates classifications, etc.
Consider substituting single-attribute identifiers for large composite identifiers
![Page 7: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/7.jpg)
7
Attributes
DepartmentDepartment
NumberLocation
NamePhone
Manager
Start date
Control ProjectsEmployees work for
Number of Employees
Detailed Conceptual Design
![Page 8: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/8.jpg)
8
Dept No unique identifier of a dept. IdentifierDept Name name of a department UniqueLocation location of a department Multi-valued Phone phone no. of a departmentEmployees no. of employees in a dept. Derived
Dept No
Dept Name
Location
Employees
Phone
Department
Detailed Conceptual Design
![Page 9: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/9.jpg)
9
Detailed Conceptual Design
ProjectProject
NameNumberLocation Leader Employee
Department Control
Proj No unique identifier of a project IdentifierProj Name name of a project UniqueLocation location of a project
Project
Proj No
Proj Name
Location
![Page 10: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/10.jpg)
10
Detailed Conceptual Design
EmployeeEmployee
NameNational IDAddressSalarySexBirth Date
Works for DepartmentSupervise Employee
Emp No
![Page 11: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/11.jpg)
11
Detailed Conceptual Design
EmployeeEmployee
Emp No unique identifier of an emp. IdentifierEmp Name name of an employee Composite First Name first name of an employee Mid Initials middle initials of an employee Last Name last name of an employeeNID national id of an employee UniqueAddress address of an employeeSalary salary of an employeeGender sex of an employeeDOB birth date of an employee
![Page 12: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/12.jpg)
12
Detailed Conceptual Design
Emp No
Emp Name
NID
Salary
Address
Employee
GenderDOB
First Name
Mid Initials
Last Name
![Page 13: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/13.jpg)
13
Detailed Conceptual Design
DependentDependent
Name Sex Birth Date Relationship
Depd Name name of a dependent Part of KeyGender sex of a dependent DOB birth date of a dependentRelation relationship of a dependent to an employee
Dependent
Depd Name
Gender
DOB
Relation
![Page 14: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/14.jpg)
14
Employee
works
Department
Project
manage
controlworks on
supervise
Dependent
has
Depd Name
GenderDOBRelation
Emp No
Emp NameNID
Salary
Address
Gender
DOB
First Name
Mid Initials
Last Name
Proj No
Proj NameLocation
Dept No
Dept Name
Location
Employees
Phone
Hours
Start d
![Page 15: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/15.jpg)
15
Entity Types
Weak Entity An entity types whose existence depends on
some other entity
Dependent
Employee
Strong (Regular) Entity An entity that exists independently of other
entity types
![Page 16: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/16.jpg)
16
Entity Types
Identifying Relationship A relationship between a weak entity type
and its owner
Identifying Owner The entity type on which the weak entity
type dependse.g. Employee is the Owner of Dependent
has
![Page 17: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/17.jpg)
17
Employee
works
Department
Project
manage
controlworks on
supervise
Dependent
has
Conceptual Design showing weak entities
![Page 18: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/18.jpg)
18
Sample Entity Definitions
Name: DepartmentType: RegularDefinition: a department of an organisationIdentifier: Dept_No
Name: DependentType: WeakDefinition: a person who is a dependent of an employee and entitle for insuranceIdentifier: Depd_Name (partial only)
![Page 19: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/19.jpg)
19
Sample Attribute Definitions
Name: Emp_NoDomain: employee identitiesDefinition: unique identifier of an employeeNull: No
Name: Emp_NameComponents: First_Name, Mid_Initials,
Last_NameDefinition: a partial identifier of a nameNull: No
![Page 20: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/20.jpg)
20
Sample Relationship Definitions
Name: Works_forType: binary 1:MDefinition: associates each employee with a
departmentConstraint: each employee must be attached to a
departmentAttributes: none
![Page 21: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/21.jpg)
21
Sample Domain Constraints
Name: Employee identitiesData Type: characterLength: 5Allowable Characters: digits
Domain Constraints A specification of the characteristics of the
data values that can be associated with one or more attributes
![Page 22: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/22.jpg)
22
Sample Domain Constraints Cont’d Name: Last name
Data Type: characterMax Length: 20
Name: DOBData Type: dateFormat: dd/mm/yyyy
dd = daymm = monthyyyy = year
![Page 23: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/23.jpg)
23
Associative Entity
An entity type that associates the instances of one or more entity types and contains attributes that are peculiar to the relationship between those entity instances
Certificate
![Page 24: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/24.jpg)
24
Completes
Date Comp
Course
CNameCourse Id
Employee
Emp NameEmp No
Certificate
Course
CNameCourse Id
Employee
Emp NameEmp No Date Comp
Cert No
4
4
30
30
11 many to may relationship many to may relationship
22 one to many relationships one to many relationships
![Page 25: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/25.jpg)
25
Associative Entity All of the relationships for the participating
entity types are “many” relationships The resulting associative entity type has
independent meaning to end users, and preferably can be identified with a single-attribute identifier
The associative entity has one or more attributes, in addition to the identifier
The associative entity participates in one or more relationships independent of the entities related in the associated relationships
![Page 26: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/26.jpg)
26
Relationships Unary Relationship
A relationship between the instances of a single entity type
e.g. Person is married to a Person (1:1) Employee manages Employees (1:M)
Binary Relationship A relationship between the instances of two entity
types
Employee
manages
![Page 27: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/27.jpg)
27
Relationships Ternary Relationship
A simultaneous relationship among the instances of three entity types
S1 P1 W1 Land 10S1 P1 W2 Sea 15S1 P2 W1 Air 20S2 P1 W1 Air 15
Part
Warehouse
SuppliesVendor
Shipping Mode
Unit Cost
![Page 28: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/28.jpg)
28
Relationships Ternary Relationship
can be treated as two many to many relationships
Part
Vendor
WarehouseSupplies
Shipping Mode
Unit Cost
supply
![Page 29: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/29.jpg)
29
Entity Relationship Model
studno name
given family
hons
slot
labmark
exammark
STUDENT
SCHOOL
YEARENROL
YEARREG
REG
TUTOR
YEARTUTOR
STAFFCOURSE
courseno
subjectequip
name
year
faculty
appraiserappraisee
APPRAISAL
TEACHm n
1 m
1
11m
n mm
1
m
1
roomno
![Page 30: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/30.jpg)
30
Superclasses, Subclasses; Specialisation & Generalisation Relationships
Subclasses and Superclasses a subclass entity type is a specialised type of
superclass entity type a subclass entity type represents a subset or
subgrouping of superclass entity type’s instances e.g. undergraduates and postgraduates are
subclasses of student superclass Attribute Inheritance
subclasses inherit properties (attributes) of their superclasses
![Page 31: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/31.jpg)
31
Constraints on Specialisation & Generalisation
Specialisation the process of defining a set of more specialised entity types of
an entity type Generalisation
the process of defining a generalised entity type from a set of entity types
Predicate/Condition defined determine the entities that will become members of each
subclass by a condition on an attribute value. All member instances of the subclass must satisfy the predicate
e.g. first years and second years are subclasses of undergraduates based on their year attribute.
User defined no condition for determining subclass membership
![Page 32: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/32.jpg)
32
Constraints on Specialisation & Generalisation
Disjointness Overlap
• the same entity instance may be a member of more than one subclass of the specialisation
Disjoint• the same entity instance may be a member of only one subclass of the
specialisation
Completeness Total
• every entity instance in the superclass must be a member of some subclass in the specialisation
Partial• an entity instance in the superclass need not be a member of any
subclass in the specialisation
![Page 33: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/33.jpg)
33
Specialisation & Generalisation Relationships
name
given family
STUDENT
studno
d
undergraduate postgraduate
thesis title
year
STAFF
tutor
1
m
![Page 34: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/34.jpg)
34
Superclasses, SubclassesSpecialisation & Generalisation Relationships
ACADEMIC ADMIN
STAFF
TECHNICAL
payroll no name
length of service
levelgrade
project
O
![Page 35: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/35.jpg)
35
Superclasses, SubclassesSpecialisation & Generalisation Relationships
EMPLOYEE STUDENT
PERSON
O
name
salaryfee
O
d
RESEARCH TEACHINGPOSTGRAD
UNDERGRAD
thesis
O
LECTURING TUTORS
address
project
FINAL YEAR
year = 3
SUPERVISOR
1-2
1-2
courseno
![Page 36: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/36.jpg)
36
Categories and Categorisation a single superclass/subclass relationship with more
than one superclass, where the superclasses represent different entity types (sometimes with different keys)
PERSONCOMPANY
U
OWNER
personid compid
duration of ownership
![Page 37: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/37.jpg)
37
Specialisation & Generalisation Option A
1. Create a relation for superclass
2. Create a relation for each subclass such that:
{primary_key of superclass} U {attributes of subclass}
key for subclass is (primary_key of superclass)
Inclusion dependency:<key>(superclass) <key>(subclass )
Covering dependency:n (number of subclasses)
<key>(subclass ) = <key>(superclass)i=1
Disjoint dependency:n (number of subclasses)
<key>(subclass ) = i=1
name
given family
STUDENT
studno
d
undergraduate postgraduate
thesis title
year
![Page 38: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/38.jpg)
38
Specialisation & Generalisation Option B1. Create a relation for each subclass such that:
{primary_key U {attributes U {attributes of of superclass} of superclass} subclass}
key for each relation is (primary_key of superclass)
•Works for total and disjoint constraints•Partial: lose any entity that is not in a subclass•Overlapping: redundancy•To recover the superclass can do an OUTER UNION on the subclass relations
name
given family
STUDENT
studno
d
undergraduate postgraduate
thesis title
year
![Page 39: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/39.jpg)
39
Specialisation & Generalisation Option C1. Create one relation such that:
{primary_key U {attributes U {attributes U {type
of superclass} of superclass} of all subclasses} attribute} key for subclass is (primary_key of superclass)
•Many ‘not-applicable’ nulls•Does away with joins•Disjoint: one type which indicates which subclass the tuple represents•Overlap: set of types = number of subclasses•Partial: type is null represents superclass
name
given family
STUDENT
studno
d
undergraduate postgraduate
thesis title
year
![Page 40: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/40.jpg)
40
Specialisation & Generalisation Overlapping
1.STAFF(payrollno,name,lengthofservice)
ACADEMIC(payrollno,level)
TECHNICAL(payrollno,project)
ADMIN(payrollno,grade)
2.ACADEMIC(payrollno,name,lengthofservice,
level)
TECHNICAL(payrollno,name,lengthofservice,
project)
ADMIN(payrollno,name,lengthofservice,grade)
3.STAFF(payrollno,name,lengthofservice,level,
project,grade,type1,type2,type3)
STAFF(payrollno,name,lengthofservice,level,
project,grade,type)
type = powerset of classes
ACADEMIC ADMIN
STAFF
TECHNICAL
payroll no name
length of service
levelgrade
project
O
![Page 41: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/41.jpg)
41
Specialisation & Generalisation Relationships
EMPLOYEE STUDENT
PERSON
O
name
salaryfee
O
d
RESEARCH TEACHINGPOSTGRAD
UNDERGRAD
thesis
O
LECTURING TUTORS
address
project
FINAL YEAR
year = 3
SUPERVISOR
1-2
1-2
courseno
![Page 42: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/42.jpg)
42
Specialisation Lattice with Shared Subclass
To be a shared subclass the superclasses must have the same key.
Staffpayroll no
Academic AdminTechnical
d
d
Manager
Admin Manager
Hourly Staff
Salaried Staff
![Page 43: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/43.jpg)
43
Categories and Categorisation A category is a subclass of the union of two or more superclasses
that can have different keys because they can be of different entity types
If defining superclasses have different keys, specify a new surrogate key
PERSONCOMPANY
U
OWNER
personid compid
duration of ownership OWNER( ??? )PERSON( ??? )COMPANY( ??? )
![Page 44: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/44.jpg)
44
a)Mapping of EER to Relational model
Create a relation for the super class. with attributes {k,a1..an}
Create a relation Li for each Si
Attributes of Li={k}U{Attributes of Si}
Constraints can be disjoint/overlapping, Total/Partial
![Page 45: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/45.jpg)
45
b)Mapping of EER to Relational model
Create a relation Li for each Si
Attributes of Li={k a1..an}U{Attributes of Si}
Constraint must be disjoint and total
![Page 46: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/46.jpg)
46
c)Mapping of EER to Relational model
Create a single relation L Attributes of L={k a1..an}U{Attributes of S1}U…
U{Attributes of Sm}U{t} ‘t’ is a type attribute that indicates the sub-
class to which each tuple belongs. This may create a lot of null values
Constraint is disjoint (total or partial) Not very space efficient hence can use a
previous method But no need of ’joins’ to get all attributes
![Page 47: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/47.jpg)
47
d)Mapping of EER to Relational model
Create a single relation L Attributes of L={k a1..an}U{Attributes of S1}U…
U{Attributes of Sm}U{t1,t2 ,..tm } ‘t’ is a type attribute that indicates the sub-
class to which each tuple belongs. This may create a lot of null values
Constraint is overlapping (total or partial) Not very space efficient hence can use a
previous method But no need of ’joins’ to get all attributes
![Page 48: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/48.jpg)
48
Mapping shared sub-classes
Option ‘a’ is usually used Options ‘c’ & ‘d’ can also be used
![Page 49: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/49.jpg)
49
Mapping of categories
If the super-classes have different keys we have to define a new key attribute called a ‘surrogate key’. When creating a relation to correspond to the category.
Create a relation to correspond to the category,include any atributes of the category.The primary key is the surrogate key
Each super-class is also mapped into a relation with its own primary key, the surrogate key becomes a foreign key for this.
![Page 50: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/50.jpg)
50
Eg. For mapping category
Person(PersonID,name,…,OwnerID) Company(CompID,name,…,OwnerID) Owner(OwnerID, OwnerType)
![Page 51: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/51.jpg)
51
Hints for EER Modelling identify entity types by searching for nouns and noun phrases assume all entities are strong and check for weak ones on a later
pass need an identifier for each strong entity assume all relationships are partial participation (optional) and
check for total (mandatory) ones on a later pass expect to keep changing your mind about whether things are
entities, relationships or attributes keep level of detail relevant and consistent (for example leave out
attributes at first) approach diagram through different views and merge them
![Page 52: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/52.jpg)
52
Review: ISA Hierarchies
Contract_Emps
namessn
Employees
lot
hourly_wages
ISA
Hourly_Emps
contractid
hours_worked
As in C++, or other PLs, attributes are inherited. If we declare A ISA B, every A entity is also considered to be a B entity.
Overlap constraints: Can Joe be an Hourly_Emps as well as a Contract_Emps entity? (Allowed/disallowed)
Covering constraints: Does every Employees entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no)
![Page 53: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/53.jpg)
53
Translating ISA Hierarchies to Relations
General approach: 3 relations: Employees, Hourly_Emps and Contract_Emps.
• Hourly_Emps: Every employee is recorded in Employees. For hourly emps, extra info recorded in Hourly_Emps (hourly_wages, hours_worked, ssn); must delete Hourly_Emps tuple if referenced Employees tuple is deleted).
• Queries involving all employees easy, those involving just Hourly_Emps require a join to get some attributes.
Alternative: Just Hourly_Emps and Contract_Emps. Hourly_Emps: ssn, name, lot, hourly_wages,
hours_worked. Each employee must be in one of these two subclasses.
![Page 54: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/54.jpg)
54
Review: Binary vs. Ternary Relationships
What are the additional constraints in the 2nd diagram?
agepname
DependentsCovers
name
Employees
ssn lot
Policies
policyid cost
Beneficiary
agepname
Dependents
policyid cost
Policies
Purchaser
name
Employees
ssn lot
Bad design
Better design
![Page 55: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/55.jpg)
55
Binary vs. Ternary Relationships (Contd.)
The key constraints allow us to combine Purchaser with Policies and Beneficiary with Dependents.
Participation constraints lead to NOT NULL constraints.
CREATE TABLE Policies ( policyid INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (policyid). FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE)
CREATE TABLE Dependents ( pname CHAR(20), age INTEGER, policyid INTEGER, PRIMARY KEY (pname, policyid). FOREIGN KEY (policyid) REFERENCES Policies, ON DELETE CASCADE)
![Page 56: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/56.jpg)
56
Views
A view is just a relation, but we store a definition, rather than a set of tuples.
CREATE VIEW YoungActiveStudents (name, grade)AS SELECT S.name, E.gradeFROM Students S, Enrolled EWHERE S.sid = E.sid and S.age<21
Views can be dropped using the DROP VIEW
command. How to handle DROP TABLE if there’s a view on the
table?• DROP TABLE command has options to let the user
specify this.
![Page 57: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/57.jpg)
57
Views and Security
Views can be used to present necessary information (or a summary), while hiding details in underlying relation(s). Given YoungStudents, but not Students or
Enrolled, we can find students s who are enrolled, but not the cid’s of the courses they are enrolled in.
![Page 58: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/58.jpg)
58
Relational Model: Summary
A tabular representation of data. Simple and intuitive, currently the most widely
used. Integrity constraints can be specified by the
DBA, based on application semantics. DBMS checks for violations. Two important ICs: primary and foreign keys In addition, we always have domain constraints.
Powerful and natural query languages exist. Rules to translate ER to relational model
![Page 59: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/59.jpg)
59
Exercise: Relationships in ER Model
Define Works_In2 table that captures all the available information in the ER diagram.
lot
dname
budgetdid
sincename
Works_In2 DepartmentsEmployees
ssn
capacity
Locations
addr
![Page 60: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/60.jpg)
60
Review: Key Constraints
Each dept has at most one manager, according to the key constraint on Manages.
Translation to relational model?
Many-to-Many1-to-1 1-to Many Many-to-1
dname
budgetdid
since
lot
name
ssn
ManagesEmployees Departments
![Page 61: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/61.jpg)
61
Translating ER Diagrams with Key Constraints
Map relationship to a table: Note that did is
the key now! Why not ssn?
Separate tables for Employees and Departments.
Since each department has a unique manager, we could instead combine Manages and Departments.
CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments)
CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees)
![Page 62: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/62.jpg)
62
Review: Participation Constraints
Does every department have a manager? If so, this is a participation constraint: the
participation of Departments in Manages is said to be total (vs. partial).• Every did value in Departments table must
appear in a row of the Manages table (with a non-null ssn value!)lot
name dnamebudgetdid
sincename dname
budgetdid
since
Manages
since
DepartmentsEmployees
ssn
Works_In
![Page 63: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/63.jpg)
63
Participation Constraints in SQL
We can capture participation constraints involving one entity set in a binary relationship, but little else (without resorting to CHECK constraints).
CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE NO ACTION)
![Page 64: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/64.jpg)
64
Review: Weak Entities
A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must
participate in a one-to-many relationship set (1 owner, many weak entities).
Weak entity set must have total participation in this identifying relationship set.
lot
name
agepname
DependentsEmployees
ssn
Policy
cost
![Page 65: 1 More on ER Model Detail Relationships 4. 2 Attributes Attribute A property or characteristic of an entity type that is of interest to the organisation.](https://reader035.fdocuments.in/reader035/viewer/2022062717/56649e4b5503460f94b3f391/html5/thumbnails/65.jpg)
65
Translating Weak Entity Sets Weak entity set and identifying
relationship set are translated into a single table. When the owner entity is deleted, all owned
weak entities must also be deleted.CREATE TABLE Dep_Policy ( pname CHAR(20), age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (pname, ssn), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE)