Relational calculus is a non-procedural query language used in relational databases to specify queries in a declarative manner. It defines the logical steps for retrieving data from a database without specifying the physical implementation details of how the query is executed. There are two main types of relational calculus: tuple calculus and domain calculus.

- Tuple Calculus (also known as tuple relational calculus): It expresses the query in terms of finding tuples that satisfy a given condition. The tuple calculus specifies the desired result set by specifying a formula with bound variables. It allows the user to specify what data they want to retrieve without specifying how to retrieve it.
- Domain Calculus (also known as domain relational calculus): It expresses the query in terms of finding values that satisfy a given condition. The domain calculus specifies the desired result set by specifying a formula with free variables. It allows the user to specify what data they want to retrieve without specifying how to retrieve it.

In both types of relational calculus, the formulas are expressed using a logical notation, typically based on first-order logic, and are evaluated on a relation or set of relations. The result of the evaluation is a set of tuples or values that satisfy the specified condition.

Relational calculus provides a foundation for the development of high-level query languages, such as SQL (Structured Query Language), which is widely used in relational database systems. These query languages translate the declarative queries specified in relational calculus into executable instructions that the database system can understand and execute efficiently.

Overall, relational calculus provides a formal and mathematical approach to expressing queries in relational databases, allowing users to focus on specifying what data they want rather than how to retrieve it.

### Why it is called Relational Calculus?

Relational calculus is called so because it is based on the concept of relations, which are the fundamental structures in relational databases. A relation in a database represents a table with rows and columns, where each row represents a tuple (collection of attribute values) and each column represents an attribute (data element).

The term “calculus” is used because relational calculus operates in a manner similar to mathematical calculus. Just as calculus deals with the manipulation and calculation of mathematical expressions, relational calculus deals with the manipulation and retrieval of data in a relational database.

Relational calculus provides a formal framework for expressing queries and constraints in a relational database system. It allows users to specify the desired data in a logical and declarative manner, similar to how mathematical calculus allows users to specify mathematical operations and transformations using symbolic notation.

By using the term “relational calculus,” the emphasis is placed on the relational model of data, which was introduced by Edgar F. Codd in the 1970s. The relational model organizes data into relations (tables) and emphasizes the use of relational algebra and relational calculus for querying and manipulating the data.

In summary, the name “relational calculus” reflects the fact that it operates within the context of the relational model of data and shares some conceptual similarities with mathematical calculus.

### Types of Relational calculus:

There are two main types of relational calculus: tuple calculus and domain calculus. Let’s explore each of them in more detail:

- Tuple Calculus (also known as Tuple Relational Calculus):
- Tuple calculus specifies the desired result set by defining a formula with bound variables.
- The formula represents a condition that the tuples in the result set must satisfy.
- Bound variables are variables that are quantified using universal (∀) or existential (∃) quantifiers.
- Universal quantifiers (∀) specify that the condition must hold for all possible values of the variable.
- Existential quantifiers (∃) specify that the condition must hold for at least one value of the variable.
- Tuple calculus queries answer the question “Which tuples satisfy the given condition?”
- The result of a tuple calculus query is a set of tuples that satisfy the specified condition.

- Domain Calculus (also known as Domain Relational Calculus):
- Domain calculus specifies the desired result set by defining a formula with free variables.
- The formula represents a condition that the values in the result set must satisfy.
- Free variables are variables that are not quantified and can take any value from the domain.
- Domain calculus queries answer the question “Which values satisfy the given condition?”
- The result of a domain calculus query is a set of values that satisfy the specified condition.

Both tuple calculus and domain calculus provide a way to express queries in a declarative manner, allowing users to specify what data they want without specifying how to retrieve it. These types of relational calculus serve as the foundation for high-level query languages, such as SQL, which are used to interact with relational databases.