Reputation: 173
We can use SQL queries for performing operations, so what is the purpose of using all the three: Relational Algebra, Tuple Relational Calculus, Domain Relational Calculus. Even if to design the query for a layman who doesn't know about the SQL Query, Relational Algebra can be used; what is the use of other two?
Upvotes: 3
Views: 1450
Reputation: 281
An SQL query directly corresponds to a query of the relational calculus. However, internally most DBMSs translate these queries to relational algebra where those can be optimized more effectively.
Therefore, it is very important to have both, relational calculus and relational algebra, for relational databases to work. In particular, Codd's Theorem is the foundation of this translation between the two that is done in DBMSs.
Upvotes: 0
Reputation: 14004
They are not used in DBMSs, but rather they are theoretical foundation on top of which database systems are built. So in a sense the question "why we need relational algebra when we have SQL" is like "why we need arithmetics when we have calculators". The math theory on top of which relational model is built is called First Order Logic. It is important to have this math foundation, because then we can prove that relational model works correctly, and can do what it claims to. Domain Relational Calculus is pretty much one to one notation for first order logic. Tuple Relational Calculus is equivalent to DRC, but it is sometimes easier to reason in. Particularly, Codd's Theorem proves equivalence of domain independent TRC to Relational Algebra. Relational Algebra is what SQL is (loosely) based on. So this shows why we needed all this theory to make sure that SQL works correctly (although SQL does violate several properties of relational model, and as a result it has several anomalies not possible in relational model).
Upvotes: 6