Relational Calculus and Algebra
Relational calculus is a non-procedural query language. It is of two types
Tuple relational calculus
{t | P(t)}
t defines the tuple and P is defined as the predicate
It is set of all tuples t such that predicate P is true for t
Domain Relational Calculus
{<x1, x2, x3,….xn> | P(x1, x2, x3….xn)}
X1, x2,…..xn are the domains out of which defined for the predicate P
Safety of expressions in tuple and domain relational calculus is to be ensured correct not only syntactically but also valid
Operations in Relational Algebra
Select Operation in Relational calculus and algebra
The select operator can be used to select a row, tuple or record in the table.
The select operator is represented as – σp(r)
For example, consider the below expression
σsubject = “database”(Books)
This represents to select the list of tuples from the books where the subject is a database.
Project Operation in Relational Algebra
Using the project operation, we can select the table or the schema in the column-wise manner.
The project operator is represented as – ∏A1, A2, An (r)
Considering the below example
∏subject, author (Books)
This represents the selection of the columns subject and author from the table books.
Union Operation in Relational Algebra
Two different relations can be combined using the union operator if both the relations have the same number of attributes.
The union operator is defined in this way – r ∪ s = { t | t ∈ r or t ∈ s}
This operator can eliminate the tuples which are duplicate.
Considering the example ∏ author (Books) ∪ ∏ author (Articles) represents the list of authors who have written the books and the articles.
Set Difference operation in Relational Algebra
This set difference operator represents the list of tuples which are present in the one set but not in the other. This is represented by the symbol – and can be defined as r-s, which represents the tuples present in the r but not in the s.
Considering the example ∏ author (Books) − ∏ author (Articles), it represents the authors who have written the books but not the articles.
Cartesian Product operation in Relational Algebra
This operation of the cartesian product combines all the tuples of both the relations. It is represented with the symbol Χ. It is denoted as rΧs, which means all the tuples in the r and s are combined.
Let us consider the example σauthor = ‘roboticelectronics’'(Books Χ Articles), which means the list of all the authors of the roboticelectronics who have written the books and the articles.
Rename operation in Relational Algebra
This rename operation allow us to rename the output relation. It is represented in this way as ρ x (E), where the output expression E is represented with the name x.
This completes the tutorial of relational calculus and algebra with the explanation related to the Relational Calculus and Algebra along with the operations in the relational algebra. For any sort of doubts or questions can reach out through the comment box.
Also read