Relational Algebra and Relational Calculus are the formal query languages for a relational model. Both form the base for the SQL language which is used in most of the relational DBMSs. Relational Algebra is a procedural language.
On the other hands, Relational Calculus is a declarative language. Relational Algebra and Relational Calculus can be further differentiated on many aspects, which I have discussed below with the help of comparison chart.
Content: Relational Algebra Vs Relational Calculus
Comparison Chart
Basis for Comparison | Relational Algebra | Relational Calculus |
---|---|---|
Basic | Relational Algebra is a Procedural language. | Relational Claculus is Declarative language. |
States | Relational Algebra states how to obtain the result. | Relational Calculus states what result we have to obtain. |
Order | Relational Algebra describes the order in which operations have to be performed. | Relational Calculus does not specify the order of operations. |
Domain | Relational Algebra is not domain dependent. | Relation Claculus can be domain dependent. |
Related | It is close to a programming language. | It is close to the natural language. |
Definition of Relational Algebra
Relational algebra presents the basic set of operations for relational model. It is a procedural language, which describes the procedure to obtain the result. Relational algebra is prescriptive because it describes the order of operations in the query that specifies how to retrieve the result of a query.
The sequence of operations in a relation algebra is called relational algebra expression. The Relational Algebra Expression either takes one relation or two relations as an input to the expression and produces a new relation as a result. The resultant relation obtained from the relational algebra expressions can be further composed to the other relational algebra expression whose result will again be a new relation.
The Relation Algebra forms the framework for implementing and optimizing queries while query processing. Relational algebra is an integral part of relational DBMS. The fundamental operation included in relational algebra are { Select (σ), Project (π), Union (∪ ), Set Difference (-), Cartesian product (×) and Rename (ρ)}.
Definition of Relational Calculus
Unlike Relational Algebra, Relational Calculus is a higher level Declarative language. In converse to the relational algebra, relational calculus defines what result is to be obtained. Like Relational Algebra, Relational Calculus does not specify the sequence of operations in which query will be evaluated.
The sequence of relational calculus operations is called relational calculus expression that also produces a new relation as a result. The Relational Calculus has two variations namely Tuple Relational Calculus and Domain Relational Calculus.
The Tuple Relational Calculus list the tuples to selected from a relation, based on a certain condition provided. It is formally denoted as:
{ t | P(t) }
Where t is the set of tuples fro which the condition P is true.
The next variation is Domain Relational Calculus, which in contrast to Tuple Relational Calculus list the attributes to be selected from a relation, based on certain condition. The formal definition of Domain Relational Calculus is as follow:
{<X1, X2, X3, . . . Xn> | P(X1, X2, X3, . . . Xn)}
Where X1, X2, X3, . . . Xn are the attributes and P is the certain condition.
Key Differences Between Relational Algebra and Relational Calculus
- The basic difference between Relational Algebra and Relational Calculus is that Relational Algebra is a Procedural language whereas, the Relational Calculus is a Non-Procedural, instead it is a Declarative language.
- The Relational Algebra defines how to obtain the result whereas, the Relational Calculus define what information the result must contain.
- Relational Algebra specifies the sequence in which operations have to be performed in the query. On the other hands, Relational calculus does not specify the sequence of operations to performed in the query.
- The Relational Algebra is not domain dependent whereas, the Relational Calculus can be domain dependent as we have Domain Relational Calculus.
- The Relational Algebra query language is closely related to programming language whereas, the Relational Calculus is closely related to the Natural Language.
Conclusion
Relational Algebra and Relational Calculus both have equivalent expressive power. The main difference between them is just that Relational Algebra specify how to retrieve data and Relational Calculus defines what data is to be retrieved.
Ameeq says
Your website is Awesome very informative. I will say that you should also upload on Software Engineering.
dipankar pal says
seriously you guys are damn cool ,,,, thanks for the easy table view difference 🙂
try to write content about software engineering and basic data structure.
Vivek says
Awesome
Brian Leong says
This website is pretty good.
Mintu says
Great Post. Very informative
Awais says
Very great and appreciate-able work.
sasank says
very informative
Xyz says
Your explanation is very informative. I praise your hard work.
But I request you to explain Safe relational calculus and unsafe relational calculus. Its differences and relate it with relational algebra.