Explain the binary operations in relational algebra (DBMS)?

Query is a question or requesting information. Query language is a language which is used to retrieve information from a database.
Query language is divided into two types −
Procedural language
Procedural language
Non-procedural language
Non-procedural language
Information is retrieved from the database by specifying the sequence of operations to be performed.
For Example − Relational algebra.
Structure Query language (SQL) is based on relational algebra.
Relational algebra consists of a set of operations that take one or two relations as an input and produces a new relation as output.
The different types of relational algebra operations are as follows −
Select operation
Select operation
Project operation
Project operation
Rename operation
Rename operation
Union operation
Union operation
Intersection operation
Intersection operation
Difference operation
Difference operation
Cartesian product operation
Cartesian product operation
Join operation
Join operation
Division operation
Division operation
Union, intersection, difference, cartesian, join, division comes under binary operation (operate on two tables).
Union operation combines the values in R1, R2 removing duplicate ones.
The syntax for the union operation is as follows −
∏ regno(R1) ∪ ∏ regno(R2)
It displays all the regno of R1 and R2.
Consider two tables R1 and R2 as shown below −
To display all the regno of R1 and R2, use the following command −
∏ regno(R1) ∪ ∏ regno(R2)
No replacement is allowed for the entry.
Union All is used for the duplicate entries.
Common entries will be shown if a common intersection is used.
It displays the common values in R1 & R2. It is denoted by ∩.
The syntax for the intersection operation is as follows −
∏ regno(R1) ∩ ∏ regno(R2)
Consider two sets,
A={1,2,4,6} and B={1,2,7}
Intersection of A and B
A ∩ B ={1,2}
Elements that are present in both sets A and B are present in the set obtained by intersection of A and B.
In relational algebra if R1 and R2 are two instances of relation then,
R1 ∩ R2 ={ x | x€ R1 and x € R2}
That is, at the intersection of R1 and R2 only those tuples will be present that are in both R1 and R2.
Find all the customers whose account is in the bank and they have taken out a loan.
The expression will be as follows −
∏Name(Depositor) ∩ ∏Name(Borrower)
So intersection of Depositor and borrower is as follows −
It combines R1 and R2 without any condition.
It is denoted by X.
Degree of R1 XR2 = degree of R1 + degree of R2
{degree = total no of columns}
Consider R1 table as given below −
Table R2 is as follows −
Therefore, the result of R1 X R2 is as follows −
It combines the relation R1 and R2 with respect to a condition. It is denoted by ⋈.
The different types of join operation are as follows −
Theta join
Theta join
Natural join
Natural join
Outer join
Outer join
Outer joinLeft outer join.Right outer join.Full outer join.
Outer join
Left outer join.
Left outer join.
Right outer join.
Right outer join.
Full outer join.
Full outer join.
If we join R1 and R2 other than the equal condition, then it is called theta join/ non-equi join.
Consider R1 table
R1 ⋈ R2 with condition R1.regno > R2.regno
In the join operation, we select those rows from the cartesian product where R1.regno>R2.regno.
Join operation = select operation + cartesian product operation
If we join R1 and R2 on equal condition then it is called natural join or equi join. Generally, join is referred to as natural join.
Natural join of R1 and R2 is as follows −
{we select those tuples from cartesian product where R1.regno=R2.regno}
R1 ⋈ R2
It is an extension of natural join to deal with missing values of relation.
Consider R1 and R2 shown below −
Outer join is of three types. These are explained below with examples.
It is denoted by R1 ⋈ R2
Here all the tuples of R1(left table) appear in output.
The mismatching values of R2 are filled with NULL.
Left outer join = natural join + mismatch / extra tuple of R1.
It is denoted by R1 ⋈ R2
Here all the tuples of R2(right table) appear in output. The mismatching values of R1 are filled with NULL.
Right outer join = natural join+ mismatch/extra tuple of R2.
It is denoted by R1 ⋈ R2.
Full outer join=left outer join U right outer join.
The diagram given below depicts the full outer join −
The division operator is used for queries which involve the ‘all’.
R1 ÷ R2 = tuples of R1 associated with all tuples of R2.
Retrieve the name of subject that is taught in all courses
÷
=
The resulting operation must have all combinations of tuples of relation S that are present in the first relation or R.