Relational calculus is a non-procedural query language used to retrieve data from relational databases. It is based on mathematical logic and set theory, and uses formulas and expressions to specify the conditions that the desired data must meet.

There are two types of relational calculus: tuple calculus and domain calculus.

Tuple calculus specifies the conditions that must be met by the tuples (rows) in a relation (table) in order to retrieve them. It uses formulas of the form {T | P(T)}, where T is a tuple and P(T) is a predicate (a logical expression that evaluates to true or false for each tuple). For example, the following formula retrieves all tuples from the CUSTOMER relation (table) where the value of the COUNTRY attribute is ‘USA’:

{<C, N, A, Cn, Cy> | COUNTRY=’USA'(C, N, A, Cn, Cy)}

Domain calculus specifies the conditions that must be met by the values in a relation in order to retrieve them. It uses formulas of the form {x | P(x)}, where x is a value and P(x) is a predicate. For example, the following formula retrieves all values from the CUSTOMER relation where the value of the COUNTRY attribute is ‘USA’:

{COUNTRY | <C, N, A, Cn, Cy>, COUNTRY=’USA'(C, N, A, Cn, Cy)}

Relational calculus is a powerful query language that allows for complex queries and expressions, but it is also more difficult to use than SQL. In practice, it is mainly used by database designers and developers to specify the conditions for database operations, while end users typically use SQL to retrieve and manipulate data.

Relational calculus is a declarative language, which means that the user only needs to specify the conditions for the desired data, and the database management system (DBMS) is responsible for figuring out how to retrieve it. This is in contrast to procedural languages like SQL, where the user needs to specify each step of the query execution.

Another advantage of relational calculus is that it is more expressive than SQL. It allows for complex queries that are difficult or impossible to express in SQL, such as queries with nested subqueries or recursive definitions. This makes it a useful tool for advanced data analysis and research.

However, there are also some limitations to relational calculus. One of the main limitations is that it does not provide a way to specify the order in which the results should be returned. This means that the DBMS can return the results in any order, which may not be what the user wants. In contrast, SQL provides the ORDER BY clause to allow the user to specify the desired order of the results.

Another limitation of relational calculus is that it is less intuitive and more difficult to learn than SQL. Since it is based on mathematical logic and set theory, it requires a strong background in mathematics and formal logic to use effectively. This makes it less accessible to non-expert users and limits its practical use in many applications.

Overall, relational calculus is a powerful and expressive query language that provides a rich set of tools for advanced data analysis and research. While it may not be as accessible or intuitive as SQL, it is a valuable tool for database designers and developers who need to specify complex conditions for database operations.

## Domain Relational Calculus (DRC)

DRC is similar to Tuple Relational Calculus (TRC), but instead of specifying conditions for tuples, it specifies conditions for individual attributes or domains. DRC uses formulas of the form {x | P(x)}, where x is a value and P(x) is a predicate (a logical expression that evaluates to true or false for each value). For example, the following formula retrieves all values from the CUSTOMER relation where the value of the COUNTRY attribute is ‘USA’:

{COUNTRY | CUSTOMER, COUNTRY=’USA’}

In this formula, CUSTOMER is the name of the relation, and COUNTRY=’USA’ is the predicate that specifies the condition for the COUNTRY attribute.

DRC can also be used to specify conditions for multiple attributes or relations. For example, the following formula retrieves all values from the ORDERS relation where the value of the PRICE attribute is greater than $100, and the value of the CUSTOMER attribute is in the set {1, 2, 3}:

{PRICE | ORDERS, CUSTOMER=1 OR CUSTOMER=2 OR CUSTOMER=3 AND PRICE>100}

DRC is a powerful query language that allows for complex queries and expressions, but it is also more difficult to use than SQL. In practice, it is mainly used by database designers and developers to specify the conditions for database operations, while end users typically use SQL to retrieve and manipulate data.