Comp 5531 – Files & Databases
Tutorial 5
Winter 2023
Concordia University
Computer Science & Software Engineering
1
Today’s Plan
From E /R Diagrams to Relational Designs/Models
❖ Converting Weak Entity Sets
❖ Converting isa-hierarchy (of entity sets)
1. Straight E/R-Style Conversion
2. OO Approach
3. Nulls Approach
2
Converting ER to Relational Model
Exercise 1: a relationship-set named works_for, specifying employee/manager
assignments.
3
Converting ER to Relational Model
Exercise 1: a relationship-set named works_for, specifying employee/manager
assignments.
4
Relational Schema
employee (employee_id, name )
works_for(employee_id, manager_id )
“Many” side is used for primary key.
Relationship involves two copies of EMPLOYEE entity set.
Converting ER to Relational Model
5
Exercise 2:
Converting ER to Relational Model
Relational Schema
job (title, level )
employee (employee-id, employee-name )
branch (branch-name, branch-city, assets )
Works-on (employee-id, branch-name, job-title )
What is the primary key of Works-on?? 6
Exercise 2:
E/R Diagram Conversions (Weak Entity Sets)
Exercise 3:Convert this E/R diagram to relational database (Textbook, Ex. 4.5.1).
7
E/R Conversion > Weak Entity Sets
Relational Database:
8
Customers(SSNo, name, addr, phone)
Flights(number, day, aircraft)
Bookings(SSNo, FltNumber, day, row, seat)
What are the Candidate Keys for Bookings?
• {SSNo, FltNumber, day}
• {FltNumber, day, row, seat}
E/R Diagram Conversion
Can we describe the weak entity set Bookings using a different
approach?
9
E/R Diagram Conversion
Exercise 4: Convert the following diagram to a relational database:
10
number
Flights
day
Customers
SSNo
name
Booking
addr
aircraft
phone
seat
row
E/R Diagram Conversion
Exercise 4: Convert the following diagram to a relational database.
11
Customers(SSNo, name, addr, phone)
Flights(number, day, aircraft)
Bookings(SSNo, FltNumber, day, row, seat)
number
Flights
day
Customers
SSNo
name
Booking
addr
aircraft
phone
seat
row
E/R Diagram Conversion
Exercise 5: Convert the following diagram to a relational database.
12
E/R Diagram Conversion
1. Isa-hierarchy using the straight E/R-Style
13
Depts (name, chair)
Courses (number, deptName, room)
LabCourses (number, deptName, computerAllocation)
E/R Diagram Conversion
2. Isa-hierarchy using the OO Approach
14
Depts (name, chair)
Courses (number, deptName, room)
LabCourses (number, deptName, room, computerAllocation)
E/R Diagram Conversion
3. Isa-hierarchy using the NULLs Approach:
15
Depts (name, chair)
Lab-Courses (number, deptName, room, computerAllocation)
E/R Conversion
Exercise 6: Convert the following diagram to a relational database:
16
E/R Diagram Conversion
1. Isa conversion using E/R –Style
17
Person (name, address)
Father (name, address)
Mother (name, address)
Child (name, address)
Married (Wname, Waddress, Hname, Haddress) PK?
Either {Wname, Waddress} OR {Hname, Haddress}
FatherOf (Cname, Caddress, Fname, Faddress)
PK {Cname, Caddress}
MotherOf (Cname, Caddress, Mname, Maddress)
ChildOf (Cname, Caddress, Pname, Paddress) PK?
18
Person (name, address)
PersonFather (name, address)
PersonMother (name, address)
PersonChild (name, address)
PersonMotherChild (name, address)
PersonFatherChild (name, address)
PersonMotherFather (name, address) Dose it mean??
PersonMotherFatherChild (name, address) Dose it mean??
Add 4 tables for the 4 diamonds:
ChildOf(personName,personAddress,childName,childAddress)
FatherOf(childName,childAddress,fatherName,fatherAddress)
MotherOf(childName,childAddress,motherName,motherAddress)
Married(husbandName,husbandAddress,wifeName,wifeAddress)
E/R Diagram Conversion
2. Isa conversion using OO Approach
Question: Can we combine the first
four tables??
E/R Diagram Conversion
2. Isa conversion using OO Approach
❖ Since in OO each entity can belong to one class only, then the m:1
relationships MotherOf and FatherOf can be added as attributes to
therelations:
PersonChild (name, address, Fname, Faddress, Mname, Maddress)
PersonMotherChild (name, address, Fname, Faddress, Mname, Maddress)
PersonFatherChild (name, address, Fname, Faddress, Mname, Maddress)
19
E/R Diagram Conversion
2. Isa conversion using OO Approach
❖ Also, Married can be added as attributes to 4 tables; PersonFather, PersonMother, PersonMotherChild,
PersonFatherChild.
❖ Should add spouse name and addrress to these tables (Sname, Saddress)!
20
PersonFather (name, address, Sname, Saddress)
PersonMother (name, address, Sname, Saddress)
PersonMotherChild (name, address, Fname, Faddress, Mname,
Maddress, Sname, Saddress)
PersonFatherChild (name, address, Fname, Faddress, Mname,
Maddress, Sname, Saddress)
❖ ChildOf
ChildOf (Cname, Caddress, Pname, Paddress)
E/R Diagram Conversion
3. Isa conversion using Nulls Approach
21
Person (name, address)
Married (Wname, Waddress, Hname, Haddress)
FatherOf (Cname, Caddress, Fname, Faddress)
MotherOf (Cname, Caddress, Mname, Maddress)
ChildOf (Cname, Caddress, Pname, Paddress)
Welcome!

Tutorial 5 solutions.pdf

  • 1.
    Comp 5531 –Files & Databases Tutorial 5 Winter 2023 Concordia University Computer Science & Software Engineering 1
  • 2.
    Today’s Plan From E/R Diagrams to Relational Designs/Models ❖ Converting Weak Entity Sets ❖ Converting isa-hierarchy (of entity sets) 1. Straight E/R-Style Conversion 2. OO Approach 3. Nulls Approach 2
  • 3.
    Converting ER toRelational Model Exercise 1: a relationship-set named works_for, specifying employee/manager assignments. 3
  • 4.
    Converting ER toRelational Model Exercise 1: a relationship-set named works_for, specifying employee/manager assignments. 4 Relational Schema employee (employee_id, name ) works_for(employee_id, manager_id ) “Many” side is used for primary key. Relationship involves two copies of EMPLOYEE entity set.
  • 5.
    Converting ER toRelational Model 5 Exercise 2:
  • 6.
    Converting ER toRelational Model Relational Schema job (title, level ) employee (employee-id, employee-name ) branch (branch-name, branch-city, assets ) Works-on (employee-id, branch-name, job-title ) What is the primary key of Works-on?? 6 Exercise 2:
  • 7.
    E/R Diagram Conversions(Weak Entity Sets) Exercise 3:Convert this E/R diagram to relational database (Textbook, Ex. 4.5.1). 7
  • 8.
    E/R Conversion >Weak Entity Sets Relational Database: 8 Customers(SSNo, name, addr, phone) Flights(number, day, aircraft) Bookings(SSNo, FltNumber, day, row, seat) What are the Candidate Keys for Bookings? • {SSNo, FltNumber, day} • {FltNumber, day, row, seat}
  • 9.
    E/R Diagram Conversion Canwe describe the weak entity set Bookings using a different approach? 9
  • 10.
    E/R Diagram Conversion Exercise4: Convert the following diagram to a relational database: 10 number Flights day Customers SSNo name Booking addr aircraft phone seat row
  • 11.
    E/R Diagram Conversion Exercise4: Convert the following diagram to a relational database. 11 Customers(SSNo, name, addr, phone) Flights(number, day, aircraft) Bookings(SSNo, FltNumber, day, row, seat) number Flights day Customers SSNo name Booking addr aircraft phone seat row
  • 12.
    E/R Diagram Conversion Exercise5: Convert the following diagram to a relational database. 12
  • 13.
    E/R Diagram Conversion 1.Isa-hierarchy using the straight E/R-Style 13 Depts (name, chair) Courses (number, deptName, room) LabCourses (number, deptName, computerAllocation)
  • 14.
    E/R Diagram Conversion 2.Isa-hierarchy using the OO Approach 14 Depts (name, chair) Courses (number, deptName, room) LabCourses (number, deptName, room, computerAllocation)
  • 15.
    E/R Diagram Conversion 3.Isa-hierarchy using the NULLs Approach: 15 Depts (name, chair) Lab-Courses (number, deptName, room, computerAllocation)
  • 16.
    E/R Conversion Exercise 6:Convert the following diagram to a relational database: 16
  • 17.
    E/R Diagram Conversion 1.Isa conversion using E/R –Style 17 Person (name, address) Father (name, address) Mother (name, address) Child (name, address) Married (Wname, Waddress, Hname, Haddress) PK? Either {Wname, Waddress} OR {Hname, Haddress} FatherOf (Cname, Caddress, Fname, Faddress) PK {Cname, Caddress} MotherOf (Cname, Caddress, Mname, Maddress) ChildOf (Cname, Caddress, Pname, Paddress) PK?
  • 18.
    18 Person (name, address) PersonFather(name, address) PersonMother (name, address) PersonChild (name, address) PersonMotherChild (name, address) PersonFatherChild (name, address) PersonMotherFather (name, address) Dose it mean?? PersonMotherFatherChild (name, address) Dose it mean?? Add 4 tables for the 4 diamonds: ChildOf(personName,personAddress,childName,childAddress) FatherOf(childName,childAddress,fatherName,fatherAddress) MotherOf(childName,childAddress,motherName,motherAddress) Married(husbandName,husbandAddress,wifeName,wifeAddress) E/R Diagram Conversion 2. Isa conversion using OO Approach Question: Can we combine the first four tables??
  • 19.
    E/R Diagram Conversion 2.Isa conversion using OO Approach ❖ Since in OO each entity can belong to one class only, then the m:1 relationships MotherOf and FatherOf can be added as attributes to therelations: PersonChild (name, address, Fname, Faddress, Mname, Maddress) PersonMotherChild (name, address, Fname, Faddress, Mname, Maddress) PersonFatherChild (name, address, Fname, Faddress, Mname, Maddress) 19
  • 20.
    E/R Diagram Conversion 2.Isa conversion using OO Approach ❖ Also, Married can be added as attributes to 4 tables; PersonFather, PersonMother, PersonMotherChild, PersonFatherChild. ❖ Should add spouse name and addrress to these tables (Sname, Saddress)! 20 PersonFather (name, address, Sname, Saddress) PersonMother (name, address, Sname, Saddress) PersonMotherChild (name, address, Fname, Faddress, Mname, Maddress, Sname, Saddress) PersonFatherChild (name, address, Fname, Faddress, Mname, Maddress, Sname, Saddress) ❖ ChildOf ChildOf (Cname, Caddress, Pname, Paddress)
  • 21.
    E/R Diagram Conversion 3.Isa conversion using Nulls Approach 21 Person (name, address) Married (Wname, Waddress, Hname, Haddress) FatherOf (Cname, Caddress, Fname, Faddress) MotherOf (Cname, Caddress, Mname, Maddress) ChildOf (Cname, Caddress, Pname, Paddress)
  • 22.