DFC20203 - LAB ACTIVITY 2 - Part 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

DFC 20203 DATABASE DESIGN

LAB ACTIVITY 2: Relational Data Model – PART 3


Duration: 4 Hours

Learning Outcomes
This activity encompasses activities 2H, 2I and 2J At

the end of this activity, you should be able to:


1. Identify the fundamental operators to retrieve information.
a. Restrict (Select)
b. Project
c. Join (outer, inner)
d. Cross Product

2. Define the traditional set of operators.


a. Union
b. Intersection
c. Difference

3. Use the operators to write the expression.

SCENARIO

Infinity Design Solution Sdn. Bhd, an advertising company wants to automate the system of
managing Human Resources (HR) data. Miss Suria was selected to be an IT programmer for
Infinity Design Solution. En. Mohamed insist to develop a system to manage staff payroll. Miss
Suria needs to prepare preliminary research about the operators and relational algebra.

INSTRUCTION:
Answer the entire questions below.

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.

Page 1 of 57
DFC 20203 DATABASE DESIGN

FUNDAMENTAL OPERATORS

There are 4 fundamental operators to retrieve information from relational database.


 Restrict ( Select )
σ<selection condition>( R )

 Project
Л <attribute list> (R)

 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))

Page 2 of 57
DFC 20203 DATABASE DESIGN

ACTIVITY
The following activities (Activity Activity 2H until Activity 2J) are based on the tables below:

STAFF1
staffNo staffName Position
00689 Samat Electric engineer
00500 Ali Web developer
00111 Anaz Programmer

STAFF2
staffNo staffName Position
00111 Anaz Programmer
00500 Ali Web developer
00689 Samat Electric engineer
00444 Azie Web developer
00123 Hazlim Technical support

PROJECT
projectNo projectName Cost
1 DADD 1 000 000
2 Programming 500 000
3 Multimedia 800 000

CUSTOMER
custNo custName projectNo staffNo
C001 Adam & co 1 00111
C010 Tegas Tulin Sdn Bhd 2 00123
C011 Wangsa Mewangi Sdn Bhd 2 00123
C007 Wawasan Sdn Bhd 5 00999
C021 Halim & Son Sdn Bhd 3 00689

Page 3 of 57
DFC 20203 DATABASE DESIGN

Activity 2H
Activity Outcome: 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.

i. Restrict (Select)

Result1 σ Position = “Web developer” ( STAFF2 )


Result1

ii. Project

Result2 Л custNo, custName, staffNo (CUSTOMER)

iii. JOIN
A. INNER JOIN

Result3 (Л staffNo, staffName, Position (STAFF2))


(Л custNo, custName, ProjNo, staffNo (CUSTOMER))

B. OUTER JOIN

Result4 (Л staffNo, staffName, Position (STAFF2))


(Л custNo, custName, ProjNo, staffNo (CUSTOMER))

iv. Cartesian Product

Result5 STAFF1 X PROJECT

Page 4 of 57
DFC 20203 DATABASE DESIGN

Activity 2I
Activity Outcome: Define the traditional set of operators.
i. Union
ii. Intersection
iii. Difference

Based on given table, generate the output base on operation below.

i. UNION

STAFF1 STAFF2

ii. INTERSECTION

STAFF1 STAFF2

iii. DIFFERENCE

Difference STAFF1 - STAFF2 Difference

STAFF2 - STAFF1

Activity 2J
Activity Outcome: 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 CUSTOMER’s relation.

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 5 of 57

You might also like