WORKBOOK ACTIVITY
Table of Contents
TOPICS
LAB
1:
LAB
2:
LAB
3:
LAB
4:
LAB
5:
PAGES
ACTIVITY Fundamentals of Database
Management System
ACTIVITY Relational Databases
3
11
ACTIVITY Relational Algebra
18
ACTIVITY Entity Relationship Model
25
ACTIVITY Structured Query Language (SQL)
32
DFC 2033 DATABASE SYSTEM
LAB
6:
ACTIVITY Database Transaction
Management
54
LAB ACTIVITY 3: Relational Algebra
Duration: 2 Hours
Learning Outcomes
This activity encompasses activities 3A, 3B and 3C
1.
a.
b.
c.
d.
2.
a.
b.
c.
3.
At the end of this activity, you should be able to:
Identify the fundamental operators to retrieve information.
Restrict (Select)
Project
Join (outer, inner)
Cross Product
Define the traditional set of operators.
Union
Intersection
Difference
Use the operators to write the expression.
THEORY
The basic set of operations for the relational model
These operations enable a user to specify basic retrieval requests.
The result of retrieval is a new relation, which may have been formed from one or more
relations.
The algebra operations thus produce new relations, which can be further manipulated
using operations of the same algebra.
FUNDAMENTAL OPERATORS
There are 4 fundamental operators to retrieve information from relational database.
Restrict ( Select )
<selection condition>( R )
Project
<attribute list> (R)
Page 2 of 9
DFC 2033 DATABASE SYSTEM
Join
Inner Join
( <attribute list> (R))
( <attribute list> (R))
Outer Join
Left Outer Join
( <attribute list> (R))
( <attribute list> (R))
Right Outer Join
( <attribute list> (R))
( <attribute list> (R))
Cross Product
( <attribute list> (R)) X ( <attribute list> (R))
TRADITIONAL OPERATORS
There are 3 traditional set operator:
Union
( <attribute list> (R)) ( <attribute list> (R))
Intersection
( <attribute list> (R))
( <attribute list> (R))
Difference
( <attribute list> (R)) ( <attribute list> (R))
ACTIVITY
The following activities (Activity 3A, Activity 3B and Activity 3C) are based on the tables below:
STAFF1
staffNo
00689
00500
00111
staffName
Samat
Ali
Anaz
Position
Electric engineer
Web developer
Programmer
STAFF2
staffNo
00111
00500
00689
00444
staffName
Anaz
Ali
Samat
Azie
Position
Programmer
Web developer
Electric engineer
Web developer
Page 3 of 9
DFC 2033 DATABASE SYSTEM
00123
Hazlim
Technical support
PROJECT
projectNo
1
2
3
projectName
DADD
Programming
Multimedia
Cost
1 000 000
500 000
800 000
CUSTOMER
custNo
C001
C010
C011
C007
C021
custName
Adam & co
Tegas Tulin Sdn Bhd
Wangsa Mewangi Sdn Bhd
Wawasan Sdn Bhd
Halim & Son Sdn Bhd
projectNo
1
2
2
5
3
staffNo
00111
00123
00123
00999
00689
Activity 3A
Activity Outcome:
a. Identify the fundamental operators to retrieve information.
i. Restrict (Select)
ii. Project
iii. Join (Outer, Inner)
iv. Cross Product
Based on given table, generate the output base on operation below.
Restrict (Select)
Result1
Result1
staffNo
Position = Web developer ( STAFF2 )
staffName
Position
00500
Ali
Web developer
00444
Azie
Web developer
Project
Result2
Result2
custNO
custNo, custName, staffNo (CUSTOMER)
custName
staffNo
Page 4 of 9
DFC 2033 DATABASE SYSTEM
C001
Adams & Co
00111
C0010
Tegas Tulin Sdn Bhd
00123
C0011
Wangsa Mewangi Sdn Bhd
00123
C007
Wawasan Sdn Bhd
00999
C021
Halim & Son Sdn Bhd
00689
JOIN
A. INNER JOIN
Result3
Result3
staffNo
0011
( staffNo, staffName, Position (STAFF2))
( custNo, custName, ProjNo, staffNo (CUSTOMER))
staffName
Position
cusNo
cusName
ProjNo
Anaz
Programmer
C001
Adams & Co
B. OUTER JOIN
Result4
( staffNo, staffName, Position (STAFF2))
Page 5 of 9
DFC 2033 DATABASE SYSTEM
( custNo, custName, ProjNo, staffNo (CUSTOMER))
Result4
Cartesian Product
Result5
STAFF1 X PROJECT
Result5
Page 6 of 9
DFC 2033 DATABASE SYSTEM
Activity 3B
Activity Outcome:
a. Define the traditional set of operators.
i. Union
ii. Intersection
iii. Difference
Based on given table, generate the output base on operation below.
UNION
STAFF1
STAFF2
INTERSECTION
STAFF1
STAFF2
Page 7 of 9
DFC 2033 DATABASE SYSTEM
DIFFERENCE
Difference STAFF1 - STAFF2
Difference STAFF2 - STAFF1
Activity 3C
Activity Outcome:
a. Use the operators to write the expression.
Based on given table, generate the expression using relational algebra on situation below.
1. Select from STAFF2 where position is Web Developer.
2. Select staff name and project number for staff 00123 in CUSTOMERs relation.
Page 8 of 9
DFC 2033 DATABASE SYSTEM
3. Select same staff name from STAFF1 and STAFF2.
4. Select staff name from STAF1 which is not in STAFF2
5. Select CUSTOMER outer join with STAFF1
Page 9 of 9