Relational Algebra is a procedural query language, which takes Relation as input and generates relation as output. SQL and relational databases primarily have their theoretical underpinnings in relational algebra.
In relational algebra, the input typically consists of a collection of one or more relations, and the output typically consists of another relation that illustrates the outcome of a query or operation on the relations in the input. Because it contains the information that the user requested for a specific query or operation, the output relation is frequently referred to as a “result set” or “temporary table.”
The following are relational algebra’s fundamental operations:
With this operation, rows from a relation that meet a predetermined condition are chosen. The relation’s attributes are used to express the condition as a logical formula.
Notation : σp(r)
Where σ stands for selection predicate and r stands for relation. p is a prepositional logic formula which may use connectors like and, or, and not. These terms may use relational operators like − =, ≠, ≥, < , >, ≤.
For instance,
σsubject = "math" and marks >45(Result)
This will return tuples(rows) from the Result table with the information of students for math subject, where marks are more than 45.
With this operation, particular relational columns (attributes) are chosen. Only the attributes that were chosen will be present in the resulting relation.
Notation − ∏A1, A2, An (r)
Where A1, A2 , An are attribute names of relation r.
Note: Duplicate rows are automatically eliminated, as relation is a set.
For instance,
∏ name, roll (Result)
This statement will output only the name and Roll number of all the students in Result table.
This operation combines two relations (with the same schema) and removes duplicates.
Notation : r U s
Where r and s are either database relations or relation result set (temporary relation).
For a union operation to be valid, the following conditions must hold −
example,
∏ name (Singers) ∪ ∏ name (Dancers)
Above operation will give us names of Students who are both dancers and singers, eliminating repetition.
This operation finds the difference between two relations (with the same schema). The resulting relation contains all the tuples in the first relation that are not in the second relation.
Notation : r − s
Finds all the tuples that are present in r but not in s.
example,
∏ name (Singers) - ∏ name (Dancers)
Above operation will give us names of Students who are singers but not dancers, eliminating repetition.
Each tuple from one relation is combined with each tuple from another relation using this operation. All the attributes from both input relations are included in the schema of the resulting relation.
Notation − r Χ s
Where r and s are relations and their output will be defined as −
r Χ s = { q t | q ∈ r and t ∈ s}
Example,
σsubject = 'math'(Result Χ Registered)
For the above query to work, both Registered and Result should have the attribute subject.
This operation renames the attributes of a relation. The resulting relation has the same tuples as the original relation, but the attribute names are changed.
Notation − ρ x (E)
Where the result of expression E is saved with name of x.
Example:
ρ(STUDENT1, STUDENT)
We can use the rename operator to rename STUDENT relation to STUDENT1.
Note: also read about Basic Concepts of RDBMS
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…