SlideShare a Scribd company logo
1 of 67
RELATIONAL ALGEBRA
Md. Zahid Hasan
Lecturer
Department of Computer
Science and Engineering
•Relation schema
–Named relation defined by a set of attribute and
domain name pairs.
•Relational database schema
–Set of relation schemas, each with a distinct
name.
•Each tuple is distinct; there are no duplicate tuples.
•Order of attributes has no significance.
•Order of tuples has no significance, theoretically.
•Relation name is distinct from all other relation
names in relational schema.
•Each cell of relation contains exactly one atomic
(single) value.
•Each attribute has a distinct name.
•Values of an attribute are all from the same domain.
•Each tuple is distinct; there are no duplicate tuples.
•Order of attributes has no significance.
•Order of tuples has no significance, theoretically.
Database Scheme
A relational database scheme, or schema,
corresponds to a set of table definitions.
Eg: product(p_id, name, category, description)
supply(p_id, s_id, qnty_per_month)
supplier(s_id, name, address, ph#)
* remember the difference between a DB instance and
a DB scheme.
SAMPLE SCHEMAS AND INSTANCES
The Schemas:
Sailors(sid: integer, sname: string, rating: integer, age: real)
Boats(bid: integer, bname: string, color: string)
Reserves(sid: integer, bid: integer, day: date)
The Instances:
What is Relational Algebra?
• Relational algebra is a procedural query language.
• It consists of the select, project, union, set
difference, Cartesian product, and rename
operations.
• Set intersection, division, natural join, and
assignment combine the fundamental operations.
• SQL is based on relational algebra
•Relational algebra and relational
calculus are formal languages
associated with the relational
model.
•Both are equivalent to one another
• It is an abstract language. We use it to express
the set of operations that any relational query
language must perform.
• Two types of operations:
• 1.set-theoretic operations: tables are essentially
sets of rows
• 2.native relational operations: focus on the
structure of the rows Query languages are
specialized languages for asking
questions,or queries,that involve the
data in database.
What are the query languages ?
Query languages
• procedural vs. non-procedural
• commercial languages have some of both
• we will study:
– relational algebra (which is procedural, i.e. tells
you how to process a query)
– relational calculus (which is non-procedural i.e.
tells what you want)
SEMANTICS OF THE SAMPLE RELATIONS
• Sailors: Entity set; lists the relevant properties of sailors.
• BoatsBoats: Entity set; lists the relevant properties of boats.
• Reserves: Relationship set: links sailors and boats by describing the
boat number and date for which a sailor made a reservation.
Example of the declarative sentences for which rows stand:
Row 1: “Sailor ’22’ reserved boat number ‘101’ on 10/10/98”.
Selection and Projection
• Selection Operator: σrating>8 (S2)
Retrieves from the current instance of relation named S2 those rows
where the value of the attribute ‘rating’ is greater than 8.
Applying the above selection operator to the sample instance of S2
shown in figure 4.2 yields the relational instance on figure 4.4 as
shown below:
• π
condition
Projection Operator πsname,rating(S2)
Retrieves from the current instance of the relation named S2 those
columns whose names are ‘sname’ and ‘rating’.
Applying the above operator to the sample instance of S2 shown in figure
4.2 yields the relational instance on figure 4.5 as shown below:
N. B.: Note that the projection operator can produce
duplicate rows in the resulting instance.
- Projection Operator (cont’d)
Similarly πage(S2) yields the following relational instance
Note here the elimination of
duplicates
SQL would yield
For πage (S2):
age
35.0
55.0
35.0
35.0
Introduction
• one of the two formal query languages of the
relational model
• collection of operators for manipulating
relations
• Operators: two types of operators
– Set Operators: Union(∪),Intersection(∩),
Difference(-), Cartesian Product (x)
– New Operators: Select (σ), Project (π), Join (⋈)
Introduction – cont’d
• A Relational Algebra Expression: a sequence
of relational algebra operators and operands
(relations), formed according to a set of rules.
• The result of evaluating a relational algebra
expression is a relation.
Selection
• Denoted by σc
(R)
• Selects the tuples (rows) from a relation R that
satisfy a certain selection condition c.
• It is a unary operator
• The resulting relation has the same attributes
as those in R.
Example 1:
SNO SNAME AGE STATE
S1 MIKE 21 IL
S2 STEVE 20 LA
S3 MARY 18 CA
S4 MING 19 NY
S5 OLGA 21 NY
S:
 σstate=‘IL’(S)
Example 2:
CNO
CNAM
E
CREDI
T
DEPT
C1
Databas
e
3 CS
C2
Statistic
s
3 MATH
C3 Tennis 1
SPORT
S
C4 Violin 4 MUSIC
C5 Golf 2
SPORT
S
C6 Piano 5 MUSIC
C:
 σCREDIT ≥ 3(C)
Example 3
SNO CNO Grade
S1 C1 90
S1 C2 80
S1 C3 75
S1 C4 70
S1 C5 100
S1 C6 60
S2 C1 90
S2 C2 80
S3 C2 90
S4 C2 80
S4 C4 85
S4 C5 100
E:
σSNO=‘S1’and CNO=‘C1’(E)
Selection - Properties
• Selection Operator is commutative
σC1(σC2(R)) = σC2(σC1(R))
• The Selection is an unary operator, it cannot
be used to select tuples from more than one
relations.
Projection
• Denoted by πL
(R), where L is list of attribute names and R is a
relation name or some other relational algebra expression.
• The resulting relation has only those attributes of R specified
in L.
• The projection is also an unary operation.
• Duplicate rows are not permitted in relational algebra.
Duplication is removed from the result.
• Duplicate rows can occur in SQL, though they may be
controlled by explicit keywords.
Projection - Example
• Example 1: πSTATE
(S)
SNO SNAME AGE STATE
S1 MIKE 21 IL
S2 STEVE 20 LA
S3 MARY 18 CA
S4 MING 19 NY
S5 OLGA 21 NY
STATE
IL
LA
CA
NY
Projection - Example
Example 2: πCNAME,DEPT
(C)
CNO
CNAM
E
CREDI
T
DEPT
C1
Databas
e
3 CS
C2
Statistic
s
3 MATH
C3 Tennis 1
SPORT
S
C4 Violin 4 MUSIC
C5 Golf 2
SPORT
S
CNAM
E
DEPT
Databas
e
CS
Statistic
s
MATH
Tennis
SPORT
S
Violin MUSIC
Golf
SPORT
S
Projection - Example
Example 3: πS#
(σSTATE=‘NY'
(S))
SNO SNAME AGE STATE
S1 MIKE 21 IL
S2 STEVE 20 LA
S3 MARY 18 CA
S4 MING 19 NY
S5 OLGA 21 NY
SNO
S4
S5
SET Operations
• UNION: R1
∪ R2
• INTERSECTION: R1
∩ R2
• DIFFERENCE: R1
- R2
• CARTESIAN PRODUCT: R1
× R2
Union Compatibility
• For operators ∪, ∩, -, the operand relations
R1(A1, A2, ..., An) and R2(B1, B2, ..., Bn)
must have the same number of attributes, and
the domains of the corresponding attributes
must be compatible; that is, dom(Ai)=dom(Bi)
for i=1,2,...,n.
• The resulting relation for ∪, ∩, or - has the
same attribute names as the first operand
relation R1 (by convention).
Union Compatibility - Examples
• Are S(SNO, SNAME, AGE, STATE) and
C(CNO, CNAME, CREDIT, DEPT) union
compatible?
• Are S(S#, SNAME, AGE, STATE) and
C(CNO, CNAME, CREDIT_HOURS,
DEPT_NAME) union compatible?
UNION, SET DIFFERENCE & SET
INTERSECT
• Union puts all tuples of two relations in one relation. To use this operator,
two conditions must hold:
1. The two relations must be of the same arity.
2. The domain of ith
attribute of the two participating relation must be
the same.
• Set difference operator computes tuples that are in one relation, but not
in another.
• Set intersect operator computes tuples that are common in two relations:
• The five fundamental operations of the relational algebra are: select,
project, cartesian product, Union, and set difference
• All other operators can be constructed using these operators
EXAMPLE
• Assume a database with the following three
relations:
Sailors (sid, sname, rating)
Boats (bid, bname, color)
Reserve (sid, bid, date)
• Query 1: Find the bid of red colored boats:
EXAMPLE
• Assume a database with the following three
relations:
Sailors (sid, sname, rating)
Boats (bid, bname, color)
Reserve (sid, bid, date)
• Query 1: Find the bid of red colored boats:
– ∏bid(бcolor=red(Boats))
EXAMPLE
• Assume a database with the following three
relations:
Sailors (sid, sname, rating)
Boats (bid, bname, color)
Reserve (sid, bid, date)
• Query 1: Find the name of sailors who have
reserved Boat number 2.
EXAMPLE
• Assume a database with the following three
relations:
Sailors (sid, sname, rating)
Boats (bid, bname, color)
Reserve (sid, bid, date)
• Query 1: Find the name of sailors who have reserved
Boat number 2.
– ∏sname(бbid=2(Sailors (sid)Reserve))
EXAMPLE
• Assume a database with the following three
relations:
Sailors (sid, sname, rating)
Boats (bid, bname, color)
Reserve (sid, bid, date)
• Query 1: Find the name of sailors who have reserved
both a red and a green boat.
Union, Intersection, Difference
• T= R U S : A tuple t is in relation T if and only
if t is in relation R or t is in relation S
• T = R ∩ S: A tuple t is in relation T if and only
if t is in both relations R and S
• T= R - S :A tuple t is in relation T if and only
if t is in R but not in S
Set-Intersection
• Denoted by the symbol .
• Results in a relation that contains only the
tuples that appear in both relations.
• R  S = R – (R – S)
• Since set-intersection can be written in terms
of set-difference, it is not a fundamental
operation.
Examples
A1 A2
1 Red
3 White
4 green
B1 B2
3 White
2 Blue
R S
Examples
A1 A2
1 Red
3 White
4 Green
2 Blue
A1 A2
3 White
R ∩S
R ∪ S
S - R
B1 B2
2 Blue
A1 A2
1 Red
4 Green
R - S
RENAME OPERATOR
• Rename operator changes the name of its
input table to its subscript,
– ρe2(Emp)
– Changes the name of Emp table to e2
RELATIONAL ALGEBRA INTRODUCTION
• Assume the following two relations:
Emp (SS#, name, age, salary, dno)
Dept (dno, dname, floor, mgrSS#)
• Relational algebra is a procedural query language, i.e., user must define
both “how” and “what” to retrieve.
• Relational algebra consists of a set of operators that consume either one
or two relations as input. An operator produces one relation as its output.
• Unary operators include: select, project, and rename
• Binary operators include: cartesian product, equality join, natural join,
join, semi-join, division, union, and set difference.
SELECT OPERATOR
• Select (б): selects tuples that satisfy a predicate; e.g., retrieve the
employees whose salary is 30,000
бSalary=30,000(Employee)
• Conjunctive ( ) and disjunctive ( ) selection predicates are allowed;
e.g., retrieve employees whose salary is higher than 30,000 and are
younger than 25 years old:
бSalary>30,000 age<25(Employee)
• Note that only selection predicates are allowed. A selection predicate
is either (1) a comparison (=, ≠, ≤, ≥, <, >) between an attribute and a
constant (e.g., salary = 30,000) or (2) a comparison between two
different attributes of the same relation (e.g., salary = age × 100).
• Note: This operator is different than the SELECT command of SQL.
<
<
<
EXAMPLE
• Emp table:
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
EXAMPLE
• Emp table:
• бSalary=30,000(Employee)
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
EXAMPLE
• Emp table:
• бSalary=30,000(Employee)
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
SS# Name Age Salary dno
4 Kathy 30 30000 5
EXAMPLE
• Emp table:
• бAge>22(Employee)
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
EXAMPLE• Emp table:
• бAge>22(Employee)
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
SS# Name Age Salary dno
1 Joe 24 20000 2
4 Kathy 30 30000 5
PROJECT OPERATOR
• Project (∏) retrieves a column. It is a unary operator
that eliminate duplicates.
e.g., name of employees:
∏ name(Employee)
e.g., name of employees earning more than 30,000:
∏ name(бSalary>30,000(Employee))
EXAMPLE
• Emp table:
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
EXAMPLE
• Emp table:
• ∏ age(Emp)
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
Age
24
20
22
30
4
EXAMPLE
• Emp table:
• ∏ name,age(бSalary=4000 (Emp) )
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
EXAMPLE
• Emp table:
• ∏ name,age(бSalary=4000 (Emp) )
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
SS# Name Age Salary dno
5 Shideh 4 4000 1
EXAMPLE
• Emp table:
• ∏ name,age(бSalary=4000 (Emp) )
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 3
3 Bob 22 27000 4
4 Kathy 30 30000 5
5 Shideh 4 4000 1
Name Age
Shideh 4
CARTESIAN PRODUCT
• Cartesian Product (R1×R2) combines two relations by
concatenating their tuples together, evaluating all
possible combinations. If the name of a column is
identical for two relations, this ambiguity is resolved
by attaching the name of each relation to a column.
e.g., Emp × Dept
– (SS#, name, age, salary, Emp.dno, Dept.dno, dname, floor,
mgrSS#)
• If t(Emp) and t(Dept) is the cardinality of the
Employee and Dept relations respectively, then the
cardinality of Emp × Dept is: t(Emp) × t(Dept)
CARTESIAN PRODUCT (Cont…)
• Example:
Emp table:
Dept table:
345 John Doe 23 25,000 1
943 Jane Java 25 28,000 2
876 Joe SQL 22 32,000 1
SS# Name age salary dno
1 Toy 1 345
2 Sho 2 943
dno dname floor mgrSS#
CARTESIAN PRODUCT (Cont…)
• Cartesian product of Emp and Dept: Emp × Dept:
34
5
John
Doe
23 25,00
0
1 1 Toy 1 345
94
3
Jane
Java
25 28,00
0
2 1 Toy 1 345
87
6
Joe SQL 22 32,00
0
1 1 Toy 1 345
34
5
John
Doe
23 25,00
0
1 2 Shoe 2 943
94
3
Jane
Java
25 28,00
0
2 2 Shoe 2 943
87 Joe SQL 22 32,00 1 2 Shoe 2 943
SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
CARTESIAN PRODUCT
• Example: retrieve the name of employees
that work in the toy department:
CARTESIAN PRODUCT
• Example: retrieve the name of employees
that work in the toy department:
– ∏name(бEmp.dno=Dept.dno(Emp × бdname=‘toy’(Dept)))
CARTESIAN PRODUCT (Cont…)
• ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept)))
345 John Doe 23 25,000 1 1 Toy 1 345
943 Jane Java 25 28,000 2 1 Toy 1 345
876 Joe SQL 22 32,000 1 1 Toy 1 345
345 John Doe 23 25,000 1 2 Shoe 2 943
943 Jane Java 25 28,000 2 2 Shoe 2 943
876 Joe SQL 22 32,000 1 2 Shoe 2 943
SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
CARTESIAN PRODUCT (Cont…)
• ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept)))
345 John
Doe
23 25,000 1 1 Toy 1 345
876 Joe
SQL
22 32,000 1 1 Toy 1 345
943 Jane
Java
25 28,000 2 2 Shoe 2 943
SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
CARTESIAN PRODUCT (Cont…)
• ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept)))
345 John
Doe
23 25,000 1 1 Toy 1 345
876 Joe SQL 22 32,000 1 1 Toy 1 345
SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
CARTESIAN PRODUCT (Cont…)
• ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept)))
John Doe
Joe SQL
Name
•Join is a derivative of Cartesian product.
•Equivalent to performing a Selection, using join
predicate as selection formula, over Cartesian
product of the two operand relations.
•One of the most difficult operations to implement
efficiently in an RDBMS and one reason why
RDBMSs have intrinsic performance problems.
•Various forms of join operation
–Natural join (defined by Codd)
–Outer join
–Theta join
–Equijoin (a particular type of Theta join)
–Semijoin
EQUALITY JOIN, NATURAL JOIN,
JOIN, SEMI-JOIN
• Equality join connects tuples from two relations that match on certain
attributes. The specified joining columns are kept in the resulting relation.
– ∏name(бdname=‘toy’(Emp Dept)))
• Natural join connects tuples from two relations that match on the
specified common attributes
– ∏name(бdname=‘toy’(Emp Dept)))
• How is an equality join between Emp and Dept using dno different than a
natural join between Emp and Dept using dno?
– Equality join: SS#, name, age, salary, Emp.dno, Dept.dno, …
– Natural join: SS#, name, age, salary, dno, dname, …
• Join is similar to equality join using different comparison operators
– A S op = {=, ≠, ≤, ≥, <, >}
att op att
(dno)
(dno)
EXAMPLE JOIN
• Equality Join, (Emp Dept)))
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 1
3 Bob 22 27000 1
4 Kathy 30 30000 2
5 Shideh 4 4000 1
EMP
dno dname floor mgrss#
1 Toy 1 5
2 Shoe 2 1
Dept
(dno)
SS# Name Age Salary EMP.dn
o
Dept.dn
o
dnam
e
floor mgrss
#
1 Joe 24 20000 2 2 Shoe 2 1
2 Mary 20 25000 1 1 Toy 1 5
3 Bob 22 27000 1 1 Toy 1 5
4 Kathy 30 30000 2 2 Shoe 2 1
5 Shideh 4 4000 1 1 Toy 1 5
EXAMPLE JOIN
• Natural Join, (Emp Dept)))
SS# Name Age Salary dno
1 Joe 24 20000 2
2 Mary 20 25000 1
3 Bob 22 27000 1
4 Kathy 30 30000 2
5 Shideh 4 4000 1
EMP
dno dname floor mgrss#
1 Toy 1 5
2 Shoe 2 1
Dept
(dno)
SS# Name Age Salary dno dname floor mgrss#
1 Joe 24 20000 2 Shoe 2 1
2 Mary 20 25000 1 Toy 1 5
3 Bob 22 27000 1 Toy 1 5
4 Kathy 30 30000 2 Shoe 2 1
5 Shideh 4 4000 1 Toy 1 5

More Related Content

What's hot (20)

Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
12 SQL
12 SQL12 SQL
12 SQL
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) Fundamentals
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 
Acid properties
Acid propertiesAcid properties
Acid properties
 
Object Based Databases
Object Based DatabasesObject Based Databases
Object Based Databases
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 

Viewers also liked

Chapter 5 : Link Layer
Chapter 5 : Link LayerChapter 5 : Link Layer
Chapter 5 : Link LayerAmin Omi
 
Transaction
TransactionTransaction
TransactionAmin Omi
 
Chapter 2 : Application Layer
Chapter 2 : Application LayerChapter 2 : Application Layer
Chapter 2 : Application LayerAmin Omi
 
Database Normalisation
Database NormalisationDatabase Normalisation
Database NormalisationAmin Omi
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShareSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

Viewers also liked (7)

Chapter 5 : Link Layer
Chapter 5 : Link LayerChapter 5 : Link Layer
Chapter 5 : Link Layer
 
Transaction
TransactionTransaction
Transaction
 
Chapter 2 : Application Layer
Chapter 2 : Application LayerChapter 2 : Application Layer
Chapter 2 : Application Layer
 
Database Normalisation
Database NormalisationDatabase Normalisation
Database Normalisation
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to Relational Algebra

Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational modelATS SBGI MIRAJ
 
lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...
lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...
lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...RajuNestham1
 
Info_Management_report-1.pptx
Info_Management_report-1.pptxInfo_Management_report-1.pptx
Info_Management_report-1.pptxChingChingErm
 
Relational Model on Database management PPT
Relational Model on Database management PPTRelational Model on Database management PPT
Relational Model on Database management PPTssuser3e0f731
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATELShashi Patel
 
Relational operation final
Relational operation finalRelational operation final
Relational operation finalStudent
 
Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization Hafiz faiz
 
Relational model
Relational modelRelational model
Relational modelRUpaliLohar
 
Relational model
Relational modelRelational model
Relational modelRUpaliLohar
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdfKavinilaa
 
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
Data Base Management system relation algebra ER diageam Sql Query -nested  qu...Data Base Management system relation algebra ER diageam Sql Query -nested  qu...
Data Base Management system relation algebra ER diageam Sql Query -nested qu...kudiyarc
 
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdf
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdfLecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdf
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdfssuserf86fba
 

Similar to Relational Algebra (20)

Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
Relational model
Relational modelRelational model
Relational model
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
lecture8Alg.ppt
lecture8Alg.pptlecture8Alg.ppt
lecture8Alg.ppt
 
lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...
lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...
lefg sdfg ssdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg sdfg d...
 
Unit 04 dbms
Unit 04 dbmsUnit 04 dbms
Unit 04 dbms
 
Info_Management_report-1.pptx
Info_Management_report-1.pptxInfo_Management_report-1.pptx
Info_Management_report-1.pptx
 
Relational Model on Database management PPT
Relational Model on Database management PPTRelational Model on Database management PPT
Relational Model on Database management PPT
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
 
Relational operation final
Relational operation finalRelational operation final
Relational operation final
 
RDBMS
RDBMSRDBMS
RDBMS
 
Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization
 
Relational model
Relational modelRelational model
Relational model
 
Relational model
Relational modelRelational model
Relational model
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf
 
Ch7
Ch7Ch7
Ch7
 
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
Data Base Management system relation algebra ER diageam Sql Query -nested  qu...Data Base Management system relation algebra ER diageam Sql Query -nested  qu...
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
 
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdf
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdfLecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdf
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdf
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 

More from Amin Omi

Chapter 8 : Memory
Chapter 8 : MemoryChapter 8 : Memory
Chapter 8 : MemoryAmin Omi
 
Pipelining
PipeliningPipelining
PipeliningAmin Omi
 
Sad lecture 1
Sad lecture 1Sad lecture 1
Sad lecture 1Amin Omi
 
Sad lecture 2
Sad lecture 2Sad lecture 2
Sad lecture 2Amin Omi
 
Sad lecture 3
Sad lecture 3Sad lecture 3
Sad lecture 3Amin Omi
 
Sad lecture 4
Sad lecture 4Sad lecture 4
Sad lecture 4Amin Omi
 
Sad lecture 5
Sad lecture 5Sad lecture 5
Sad lecture 5Amin Omi
 
Chapter 05
Chapter 05Chapter 05
Chapter 05Amin Omi
 
Transaction
TransactionTransaction
TransactionAmin Omi
 
Normalization
NormalizationNormalization
NormalizationAmin Omi
 
Transport Layer
Transport LayerTransport Layer
Transport LayerAmin Omi
 
Basic health tips
Basic health tipsBasic health tips
Basic health tipsAmin Omi
 
Style of living
Style of livingStyle of living
Style of livingAmin Omi
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsackAmin Omi
 
Basic SQL Command
Basic SQL CommandBasic SQL Command
Basic SQL CommandAmin Omi
 

More from Amin Omi (19)

Chapter 8 : Memory
Chapter 8 : MemoryChapter 8 : Memory
Chapter 8 : Memory
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 
Pipelining
PipeliningPipelining
Pipelining
 
Sad lecture 1
Sad lecture 1Sad lecture 1
Sad lecture 1
 
Sad lecture 2
Sad lecture 2Sad lecture 2
Sad lecture 2
 
Sad lecture 3
Sad lecture 3Sad lecture 3
Sad lecture 3
 
Sad lecture 4
Sad lecture 4Sad lecture 4
Sad lecture 4
 
Sad lecture 5
Sad lecture 5Sad lecture 5
Sad lecture 5
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Chapter04
Chapter04Chapter04
Chapter04
 
Chapter02
Chapter02Chapter02
Chapter02
 
Chapter01
Chapter01Chapter01
Chapter01
 
Transaction
TransactionTransaction
Transaction
 
Normalization
NormalizationNormalization
Normalization
 
Transport Layer
Transport LayerTransport Layer
Transport Layer
 
Basic health tips
Basic health tipsBasic health tips
Basic health tips
 
Style of living
Style of livingStyle of living
Style of living
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Basic SQL Command
Basic SQL CommandBasic SQL Command
Basic SQL Command
 

Recently uploaded

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAbdelrhman abooda
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 

Recently uploaded (20)

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 

Relational Algebra

  • 1. RELATIONAL ALGEBRA Md. Zahid Hasan Lecturer Department of Computer Science and Engineering
  • 2. •Relation schema –Named relation defined by a set of attribute and domain name pairs. •Relational database schema –Set of relation schemas, each with a distinct name. •Each tuple is distinct; there are no duplicate tuples. •Order of attributes has no significance. •Order of tuples has no significance, theoretically. •Relation name is distinct from all other relation names in relational schema. •Each cell of relation contains exactly one atomic (single) value. •Each attribute has a distinct name. •Values of an attribute are all from the same domain. •Each tuple is distinct; there are no duplicate tuples. •Order of attributes has no significance. •Order of tuples has no significance, theoretically.
  • 3. Database Scheme A relational database scheme, or schema, corresponds to a set of table definitions. Eg: product(p_id, name, category, description) supply(p_id, s_id, qnty_per_month) supplier(s_id, name, address, ph#) * remember the difference between a DB instance and a DB scheme.
  • 4. SAMPLE SCHEMAS AND INSTANCES The Schemas: Sailors(sid: integer, sname: string, rating: integer, age: real) Boats(bid: integer, bname: string, color: string) Reserves(sid: integer, bid: integer, day: date) The Instances:
  • 5.
  • 6. What is Relational Algebra? • Relational algebra is a procedural query language. • It consists of the select, project, union, set difference, Cartesian product, and rename operations. • Set intersection, division, natural join, and assignment combine the fundamental operations. • SQL is based on relational algebra
  • 7. •Relational algebra and relational calculus are formal languages associated with the relational model. •Both are equivalent to one another
  • 8. • It is an abstract language. We use it to express the set of operations that any relational query language must perform. • Two types of operations: • 1.set-theoretic operations: tables are essentially sets of rows • 2.native relational operations: focus on the structure of the rows Query languages are specialized languages for asking questions,or queries,that involve the data in database. What are the query languages ?
  • 9. Query languages • procedural vs. non-procedural • commercial languages have some of both • we will study: – relational algebra (which is procedural, i.e. tells you how to process a query) – relational calculus (which is non-procedural i.e. tells what you want)
  • 10. SEMANTICS OF THE SAMPLE RELATIONS • Sailors: Entity set; lists the relevant properties of sailors. • BoatsBoats: Entity set; lists the relevant properties of boats. • Reserves: Relationship set: links sailors and boats by describing the boat number and date for which a sailor made a reservation. Example of the declarative sentences for which rows stand: Row 1: “Sailor ’22’ reserved boat number ‘101’ on 10/10/98”.
  • 11. Selection and Projection • Selection Operator: σrating>8 (S2) Retrieves from the current instance of relation named S2 those rows where the value of the attribute ‘rating’ is greater than 8. Applying the above selection operator to the sample instance of S2 shown in figure 4.2 yields the relational instance on figure 4.4 as shown below: • π condition
  • 12. Projection Operator πsname,rating(S2) Retrieves from the current instance of the relation named S2 those columns whose names are ‘sname’ and ‘rating’. Applying the above operator to the sample instance of S2 shown in figure 4.2 yields the relational instance on figure 4.5 as shown below: N. B.: Note that the projection operator can produce duplicate rows in the resulting instance.
  • 13. - Projection Operator (cont’d) Similarly πage(S2) yields the following relational instance Note here the elimination of duplicates SQL would yield For πage (S2): age 35.0 55.0 35.0 35.0
  • 14. Introduction • one of the two formal query languages of the relational model • collection of operators for manipulating relations • Operators: two types of operators – Set Operators: Union(∪),Intersection(∩), Difference(-), Cartesian Product (x) – New Operators: Select (σ), Project (π), Join (⋈)
  • 15. Introduction – cont’d • A Relational Algebra Expression: a sequence of relational algebra operators and operands (relations), formed according to a set of rules. • The result of evaluating a relational algebra expression is a relation.
  • 16. Selection • Denoted by σc (R) • Selects the tuples (rows) from a relation R that satisfy a certain selection condition c. • It is a unary operator • The resulting relation has the same attributes as those in R.
  • 17. Example 1: SNO SNAME AGE STATE S1 MIKE 21 IL S2 STEVE 20 LA S3 MARY 18 CA S4 MING 19 NY S5 OLGA 21 NY S:  σstate=‘IL’(S)
  • 18. Example 2: CNO CNAM E CREDI T DEPT C1 Databas e 3 CS C2 Statistic s 3 MATH C3 Tennis 1 SPORT S C4 Violin 4 MUSIC C5 Golf 2 SPORT S C6 Piano 5 MUSIC C:  σCREDIT ≥ 3(C)
  • 19. Example 3 SNO CNO Grade S1 C1 90 S1 C2 80 S1 C3 75 S1 C4 70 S1 C5 100 S1 C6 60 S2 C1 90 S2 C2 80 S3 C2 90 S4 C2 80 S4 C4 85 S4 C5 100 E: σSNO=‘S1’and CNO=‘C1’(E)
  • 20.
  • 21. Selection - Properties • Selection Operator is commutative σC1(σC2(R)) = σC2(σC1(R)) • The Selection is an unary operator, it cannot be used to select tuples from more than one relations.
  • 22. Projection • Denoted by πL (R), where L is list of attribute names and R is a relation name or some other relational algebra expression. • The resulting relation has only those attributes of R specified in L. • The projection is also an unary operation. • Duplicate rows are not permitted in relational algebra. Duplication is removed from the result. • Duplicate rows can occur in SQL, though they may be controlled by explicit keywords.
  • 23. Projection - Example • Example 1: πSTATE (S) SNO SNAME AGE STATE S1 MIKE 21 IL S2 STEVE 20 LA S3 MARY 18 CA S4 MING 19 NY S5 OLGA 21 NY STATE IL LA CA NY
  • 24. Projection - Example Example 2: πCNAME,DEPT (C) CNO CNAM E CREDI T DEPT C1 Databas e 3 CS C2 Statistic s 3 MATH C3 Tennis 1 SPORT S C4 Violin 4 MUSIC C5 Golf 2 SPORT S CNAM E DEPT Databas e CS Statistic s MATH Tennis SPORT S Violin MUSIC Golf SPORT S
  • 25. Projection - Example Example 3: πS# (σSTATE=‘NY' (S)) SNO SNAME AGE STATE S1 MIKE 21 IL S2 STEVE 20 LA S3 MARY 18 CA S4 MING 19 NY S5 OLGA 21 NY SNO S4 S5
  • 26. SET Operations • UNION: R1 ∪ R2 • INTERSECTION: R1 ∩ R2 • DIFFERENCE: R1 - R2 • CARTESIAN PRODUCT: R1 × R2
  • 27. Union Compatibility • For operators ∪, ∩, -, the operand relations R1(A1, A2, ..., An) and R2(B1, B2, ..., Bn) must have the same number of attributes, and the domains of the corresponding attributes must be compatible; that is, dom(Ai)=dom(Bi) for i=1,2,...,n. • The resulting relation for ∪, ∩, or - has the same attribute names as the first operand relation R1 (by convention).
  • 28. Union Compatibility - Examples • Are S(SNO, SNAME, AGE, STATE) and C(CNO, CNAME, CREDIT, DEPT) union compatible? • Are S(S#, SNAME, AGE, STATE) and C(CNO, CNAME, CREDIT_HOURS, DEPT_NAME) union compatible?
  • 29.
  • 30. UNION, SET DIFFERENCE & SET INTERSECT • Union puts all tuples of two relations in one relation. To use this operator, two conditions must hold: 1. The two relations must be of the same arity. 2. The domain of ith attribute of the two participating relation must be the same. • Set difference operator computes tuples that are in one relation, but not in another. • Set intersect operator computes tuples that are common in two relations: • The five fundamental operations of the relational algebra are: select, project, cartesian product, Union, and set difference • All other operators can be constructed using these operators
  • 31. EXAMPLE • Assume a database with the following three relations: Sailors (sid, sname, rating) Boats (bid, bname, color) Reserve (sid, bid, date) • Query 1: Find the bid of red colored boats:
  • 32. EXAMPLE • Assume a database with the following three relations: Sailors (sid, sname, rating) Boats (bid, bname, color) Reserve (sid, bid, date) • Query 1: Find the bid of red colored boats: – ∏bid(бcolor=red(Boats))
  • 33. EXAMPLE • Assume a database with the following three relations: Sailors (sid, sname, rating) Boats (bid, bname, color) Reserve (sid, bid, date) • Query 1: Find the name of sailors who have reserved Boat number 2.
  • 34. EXAMPLE • Assume a database with the following three relations: Sailors (sid, sname, rating) Boats (bid, bname, color) Reserve (sid, bid, date) • Query 1: Find the name of sailors who have reserved Boat number 2. – ∏sname(бbid=2(Sailors (sid)Reserve))
  • 35. EXAMPLE • Assume a database with the following three relations: Sailors (sid, sname, rating) Boats (bid, bname, color) Reserve (sid, bid, date) • Query 1: Find the name of sailors who have reserved both a red and a green boat.
  • 36. Union, Intersection, Difference • T= R U S : A tuple t is in relation T if and only if t is in relation R or t is in relation S • T = R ∩ S: A tuple t is in relation T if and only if t is in both relations R and S • T= R - S :A tuple t is in relation T if and only if t is in R but not in S
  • 37. Set-Intersection • Denoted by the symbol . • Results in a relation that contains only the tuples that appear in both relations. • R  S = R – (R – S) • Since set-intersection can be written in terms of set-difference, it is not a fundamental operation.
  • 38. Examples A1 A2 1 Red 3 White 4 green B1 B2 3 White 2 Blue R S
  • 39. Examples A1 A2 1 Red 3 White 4 Green 2 Blue A1 A2 3 White R ∩S R ∪ S S - R B1 B2 2 Blue A1 A2 1 Red 4 Green R - S
  • 40. RENAME OPERATOR • Rename operator changes the name of its input table to its subscript, – ρe2(Emp) – Changes the name of Emp table to e2
  • 41. RELATIONAL ALGEBRA INTRODUCTION • Assume the following two relations: Emp (SS#, name, age, salary, dno) Dept (dno, dname, floor, mgrSS#) • Relational algebra is a procedural query language, i.e., user must define both “how” and “what” to retrieve. • Relational algebra consists of a set of operators that consume either one or two relations as input. An operator produces one relation as its output. • Unary operators include: select, project, and rename • Binary operators include: cartesian product, equality join, natural join, join, semi-join, division, union, and set difference.
  • 42. SELECT OPERATOR • Select (б): selects tuples that satisfy a predicate; e.g., retrieve the employees whose salary is 30,000 бSalary=30,000(Employee) • Conjunctive ( ) and disjunctive ( ) selection predicates are allowed; e.g., retrieve employees whose salary is higher than 30,000 and are younger than 25 years old: бSalary>30,000 age<25(Employee) • Note that only selection predicates are allowed. A selection predicate is either (1) a comparison (=, ≠, ≤, ≥, <, >) between an attribute and a constant (e.g., salary = 30,000) or (2) a comparison between two different attributes of the same relation (e.g., salary = age × 100). • Note: This operator is different than the SELECT command of SQL. < < <
  • 43. EXAMPLE • Emp table: SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1
  • 44. EXAMPLE • Emp table: • бSalary=30,000(Employee) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1
  • 45. EXAMPLE • Emp table: • бSalary=30,000(Employee) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1 SS# Name Age Salary dno 4 Kathy 30 30000 5
  • 46. EXAMPLE • Emp table: • бAge>22(Employee) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1
  • 47. EXAMPLE• Emp table: • бAge>22(Employee) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1 SS# Name Age Salary dno 1 Joe 24 20000 2 4 Kathy 30 30000 5
  • 48. PROJECT OPERATOR • Project (∏) retrieves a column. It is a unary operator that eliminate duplicates. e.g., name of employees: ∏ name(Employee) e.g., name of employees earning more than 30,000: ∏ name(бSalary>30,000(Employee))
  • 49. EXAMPLE • Emp table: SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1
  • 50. EXAMPLE • Emp table: • ∏ age(Emp) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1 Age 24 20 22 30 4
  • 51. EXAMPLE • Emp table: • ∏ name,age(бSalary=4000 (Emp) ) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1
  • 52. EXAMPLE • Emp table: • ∏ name,age(бSalary=4000 (Emp) ) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1 SS# Name Age Salary dno 5 Shideh 4 4000 1
  • 53. EXAMPLE • Emp table: • ∏ name,age(бSalary=4000 (Emp) ) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 3 3 Bob 22 27000 4 4 Kathy 30 30000 5 5 Shideh 4 4000 1 Name Age Shideh 4
  • 54. CARTESIAN PRODUCT • Cartesian Product (R1×R2) combines two relations by concatenating their tuples together, evaluating all possible combinations. If the name of a column is identical for two relations, this ambiguity is resolved by attaching the name of each relation to a column. e.g., Emp × Dept – (SS#, name, age, salary, Emp.dno, Dept.dno, dname, floor, mgrSS#) • If t(Emp) and t(Dept) is the cardinality of the Employee and Dept relations respectively, then the cardinality of Emp × Dept is: t(Emp) × t(Dept)
  • 55. CARTESIAN PRODUCT (Cont…) • Example: Emp table: Dept table: 345 John Doe 23 25,000 1 943 Jane Java 25 28,000 2 876 Joe SQL 22 32,000 1 SS# Name age salary dno 1 Toy 1 345 2 Sho 2 943 dno dname floor mgrSS#
  • 56. CARTESIAN PRODUCT (Cont…) • Cartesian product of Emp and Dept: Emp × Dept: 34 5 John Doe 23 25,00 0 1 1 Toy 1 345 94 3 Jane Java 25 28,00 0 2 1 Toy 1 345 87 6 Joe SQL 22 32,00 0 1 1 Toy 1 345 34 5 John Doe 23 25,00 0 1 2 Shoe 2 943 94 3 Jane Java 25 28,00 0 2 2 Shoe 2 943 87 Joe SQL 22 32,00 1 2 Shoe 2 943 SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
  • 57. CARTESIAN PRODUCT • Example: retrieve the name of employees that work in the toy department:
  • 58. CARTESIAN PRODUCT • Example: retrieve the name of employees that work in the toy department: – ∏name(бEmp.dno=Dept.dno(Emp × бdname=‘toy’(Dept)))
  • 59. CARTESIAN PRODUCT (Cont…) • ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept))) 345 John Doe 23 25,000 1 1 Toy 1 345 943 Jane Java 25 28,000 2 1 Toy 1 345 876 Joe SQL 22 32,000 1 1 Toy 1 345 345 John Doe 23 25,000 1 2 Shoe 2 943 943 Jane Java 25 28,000 2 2 Shoe 2 943 876 Joe SQL 22 32,000 1 2 Shoe 2 943 SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
  • 60. CARTESIAN PRODUCT (Cont…) • ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept))) 345 John Doe 23 25,000 1 1 Toy 1 345 876 Joe SQL 22 32,000 1 1 Toy 1 345 943 Jane Java 25 28,000 2 2 Shoe 2 943 SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
  • 61. CARTESIAN PRODUCT (Cont…) • ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept))) 345 John Doe 23 25,000 1 1 Toy 1 345 876 Joe SQL 22 32,000 1 1 Toy 1 345 SS# Name age salary Emp.dno Dept.dno dname floor mgrSS#
  • 62. CARTESIAN PRODUCT (Cont…) • ∏name(бdname=‘toy’(бEmp.dno=Dept.dno(Emp × Dept))) John Doe Joe SQL Name
  • 63.
  • 64. •Join is a derivative of Cartesian product. •Equivalent to performing a Selection, using join predicate as selection formula, over Cartesian product of the two operand relations. •One of the most difficult operations to implement efficiently in an RDBMS and one reason why RDBMSs have intrinsic performance problems. •Various forms of join operation –Natural join (defined by Codd) –Outer join –Theta join –Equijoin (a particular type of Theta join) –Semijoin
  • 65. EQUALITY JOIN, NATURAL JOIN, JOIN, SEMI-JOIN • Equality join connects tuples from two relations that match on certain attributes. The specified joining columns are kept in the resulting relation. – ∏name(бdname=‘toy’(Emp Dept))) • Natural join connects tuples from two relations that match on the specified common attributes – ∏name(бdname=‘toy’(Emp Dept))) • How is an equality join between Emp and Dept using dno different than a natural join between Emp and Dept using dno? – Equality join: SS#, name, age, salary, Emp.dno, Dept.dno, … – Natural join: SS#, name, age, salary, dno, dname, … • Join is similar to equality join using different comparison operators – A S op = {=, ≠, ≤, ≥, <, >} att op att (dno) (dno)
  • 66. EXAMPLE JOIN • Equality Join, (Emp Dept))) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 1 3 Bob 22 27000 1 4 Kathy 30 30000 2 5 Shideh 4 4000 1 EMP dno dname floor mgrss# 1 Toy 1 5 2 Shoe 2 1 Dept (dno) SS# Name Age Salary EMP.dn o Dept.dn o dnam e floor mgrss # 1 Joe 24 20000 2 2 Shoe 2 1 2 Mary 20 25000 1 1 Toy 1 5 3 Bob 22 27000 1 1 Toy 1 5 4 Kathy 30 30000 2 2 Shoe 2 1 5 Shideh 4 4000 1 1 Toy 1 5
  • 67. EXAMPLE JOIN • Natural Join, (Emp Dept))) SS# Name Age Salary dno 1 Joe 24 20000 2 2 Mary 20 25000 1 3 Bob 22 27000 1 4 Kathy 30 30000 2 5 Shideh 4 4000 1 EMP dno dname floor mgrss# 1 Toy 1 5 2 Shoe 2 1 Dept (dno) SS# Name Age Salary dno dname floor mgrss# 1 Joe 24 20000 2 Shoe 2 1 2 Mary 20 25000 1 Toy 1 5 3 Bob 22 27000 1 Toy 1 5 4 Kathy 30 30000 2 Shoe 2 1 5 Shideh 4 4000 1 Toy 1 5