0% found this document useful (0 votes)
9 views23 pages

Lecture 7-8

The document provides an introduction to the relational model, covering various operations such as select, project, union, set difference, intersection, Cartesian product, and join operations. It includes practical exercises related to these operations, focusing on a case study of a real estate database. Additionally, it suggests readings for further understanding of database systems.

Uploaded by

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

Lecture 7-8

The document provides an introduction to the relational model, covering various operations such as select, project, union, set difference, intersection, Cartesian product, and join operations. It includes practical exercises related to these operations, focusing on a case study of a real estate database. Additionally, it suggests readings for further understanding of database systems.

Uploaded by

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

Lecture 7-8

Introduction to relational Model

Marina Gul
Sukkur IBA University Khairpur Campus
2 Agenda
The Relational Algebra
Select Operation
Project Operation
Union Operation
Set Difference Operation
Set intersection Operation
Cartesian Product Operation
Rename Operation
Join Operations
Relational schema for part of the DreamHome
3 case study
4
5 Practice
List all cities where there is either a branch office or a property for rent.
6 Set Difference Operation (r – s)
The set-difference operation, denoted by −, allows us to find
tuples that are in one relation but are not in another. The
expression r − s produces a relation containing those tuples in r
but not in s.
Notation: r – s
Set differences must be taken between compatible relations.
1. r and s must have the same arity
2. attribute domains of r and s must be compatible

r –s
7 Practice
List all cities where there is a branch office but no properties for rent.
8 Practice
Find all the courses taught in the Fall 2009 semester but not in Spring 2010
semester.
9 Set-Intersection Operation r  s
The set-intersection operation, denoted by  , allows us to find
tuples that are in common in both relation.
Notation: r  s
Assume:
1. r, s have the same arity
2. attributes of r and s are compatible

Note: r  s = r – (r – s)

rs
1
0
Practice
List all cities where there is both a branch office and property for rent.
1
1
Cartesian-Product Operation r x s
The Cartesian-product operation, denoted by a cross (×),
allows us to combine information from any two relations.

Notation: r x s

Assuming:
• the attributes of r(R) and s(S) are disjoint. (That is, R  S
= ).
• If attributes of r(R) and s(S) are not disjoint, then
renaming must be used.

rxs
1
2
Practice
List the names and comments of all clients who have viewed a
property for rent.
The names of clients are held in the Client relation and the details of
viewings are held in the Viewing relation. To obtain the list of clients
and the comments on properties they have viewed, we need to
combine these two relations:

In its present form, this relation contains more information than we


require. For example, the first tuple of this relation contains different
clientNo values. To obtain the required list, we need to carry out a
Selection operation on this relation to extract those tuples where
Client.clientNo =Viewing.clientNo. The complete operation is thus:
1
3
1
4
Practice
Find the names of all instructors in the Physics department together with the
course id of all courses they taught.
1
5
1  x ( A1 , A2 ,..., An ) ( E )
Rename Operation
6

Allows us to name, the results of relational-algebra expressions


and to refer a relation by more than one name.

Notation:  x (E) returns the expression E under the name X

 x (n,
If a relational-algebra expression E has arity A2 ,..., An ) ( E )
A1 ,then

returns the result of expression E under the name X, and with the
attributes renamed to A1 , A2 , …., An .
1
7
University Schema
1
8
1
9
Practice
Find the highest salary in the university.

Strategy
(1) compute first a temporary relation consisting of those salaries that are not
the largest and
(2) take the set difference between the relation salary (instructor) and the
temporary relation just computed, to obtain the result.
2
0
Practice
Find the highest salary in the university.
2
Function of the relational algebra
1 operations
2
2
Practice Exercise
Show records of physics department.
Show instructor table without the dept_name attribute
Find all courses taught in the Fall 2009 semester, or in the Spring
2010 semester, or in both using union operation
Find all courses taught in the Fall 2009 semester, but not in the
Spring 2010 semester
2
3
Suggested Reading
Chapter 5 of Database Systems: A Practical Approach to Design,
Implementation, and Management by Thomas Conolly 6th Edition
Chapter 6 of Database System Concepts by Abraham Silberschatz

You might also like