0% found this document useful (0 votes)
105 views9 pages

Lab Activity 3 DD

This lab activity covers relational algebra operators including selection, projection, join, and Cartesian product. It aims to help students identify fundamental operators, define traditional set operators like union, intersection, and difference, and write expressions using the operators. Students will perform activities applying selection, projection, join, and Cartesian product on sample tables and calculate unions, intersections, and differences of relations.

Uploaded by

Nurul Anisss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views9 pages

Lab Activity 3 DD

This lab activity covers relational algebra operators including selection, projection, join, and Cartesian product. It aims to help students identify fundamental operators, define traditional set operators like union, intersection, and difference, and write expressions using the operators. Students will perform activities applying selection, projection, join, and Cartesian product on sample tables and calculate unions, intersections, and differences of relations.

Uploaded by

Nurul Anisss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

LAB ACTIVITY 3: Relational Algebra

Duration: 2 Hours

Learning Outcomes
This activity encompasses activities 3A, 3B and 3C

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.

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)

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

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 σ Position =
“Web developer” ( STAFF2 ) Result1

StaffNo StaffName Position

00500 Ali Web developer

00444 Azie Web developer

Project

Result2 Л custNo, custName, staffNo (CUSTOMER)

Result2
custNo custName staffNo

C001 Adam & co 00111

C010 Tegas Tulin Sdn Bhd 00123

C011 Wangsa Mewangi Sdn Bhd 00123

C007 Wawasan Sdn Bhd 00999

C021 Halim & Son Sdn Bhd 00689

JOIN
A. INNER JOIN

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


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

Result3

staffNo staffName Position custNo custName ProjNo

00111 Anaz Programmer C001 Adam & co 1


Technical Tegas Tulin
00123 Hazlim support
C0101 Sdn Bhd 2
C0101 Wangsa Mewangi
Sdn Bhd
00123 Hazlim Technical 2
support
Electric engineer 021 Halim & Son 3
00689 Sama Sdn Bhd
B. OUTER JOIN
Result4 (Л staffNo, staffName, Position (STAFF2))
(Л custNo, custName, ProjNo, staffNo (CUSTOMER))

Result4
Position
staffNo staffName custNo custName ProjNo

00111 Anaz Programmer C001 Adam & co 1


Tegas Tulin
Ali Web Sdn Bhd 2
00500 developer C010
Electric Wangsa
00689 Samat engineer C011
Mewangi Sdn 2
Bhd
00444 Azie Web Null Null Null
developer
00123 Hazlim Technical C010 Tegas Tulin 2
support Sdn Bhd
00123 Hazlim Technical C011 Wangsa 2
support Mewangi
Sdn Bhd
00999 Null Null C007 Wawasan 5
Sdn Bhd
Cartesian Product

Result5 STAFF1 X
PROJECT

Result5

staffNo staffNo Position projectNo projectName Cost

00689 Samat Electric engineer 1 DADD 1000 000

00689 Samat Electric engineer 2 Programming 500 000

00689 Samat Electric engineer 3 Multimedia 800 000

00500 Ali Web developer 1 DADD 1000 000

00500 Ali Web developer 2 Programming 500 000

00500 Ali Web developer 3 Multimedia 800 000

00111 Anaz Programmer 1 DADD 1000 000

00111 Anaz Programmer 2 Programming 500 000

00111 Anaz Programmer 3 Multimedia 800 000

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
staffName Position
staffNo
Samat
00689 Electric engineer

00500 Ali Web developer

00111 Programmer
Anaz

00444 Azie Web developer

00123 Hazlim Technical support

INTERSECTION

STAFF1 STAFF2

staffNo staffName Position

00689 Samat Electric engineer

00500 Ali Web developer

00111 Anaz Programmer


DIFFERENCE

Difference STAFF1 - STAFF2


staffNo staffName Position

00689 Samat Electric engineer

00500 Ali Web developer

00111 Anaz Programmer

Difference STAFF2 - STAFF1

staffNo staffName Position

00444 Azie Web developer


00123 Hazlim Technical support

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.

1. Select from STAFF2 where position is Web Developer.


• σ Position = “Web developer” ( staff2 )
affNo affName sition
00500 Ali Web developer
00444 Azie Web developer

2. Select staff name and project number for staff 00123 in CUSTOMER’s
relation.

• Л staffNo,staffName,projectNumber (CUSTOMER)

affNo affName ojectNumber


00123 Hazlim 2
3. Select same staff name from STAFF1 and STAFF2.

Л staffname (staff 1) staffname (staff 2)


affName
Samat
Ali
Anaz
4. Select staff name from STAF1 which is not in STAFF2

 STAFF1 STAFF2

staffNo staffName Position


00444 Azie Web developer
00123 Hazlim Technical support

5. Select CUSTOMER outer join with STAFF1

 ((Л staffNo, staffName, Position (STAFF1))


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

You might also like