Tuple relational calculus is a formal query language that we use to retrieve information from the relational database. It is a non-procedural query language, that only states what information has to be retrieved but, it does not state how the particular information has to be retrieved.

We also refer to the tuple relational calculus as a declarative query language as it allows the user to declare what data or information he is interested in. In the section, ahead we will discuss tuple relational calculus in detail.

## Tuple Relation Calculus:

### 1. Syntax of Tuple Relation Calculus

The syntax of query in tuple relational calculus is:

*{t | P(t)} *

In the syntax above *t* is the set of all the tuples that we want in our result provided that the specified predicate is true for *t*. The tuple relational calculus query expression may result in one or more than one tuple. In a more expressive way, the syntax of query in tuple relation calculus is:

*{t _{1}.A_{j}, t_{2}.A_{k}, …, t_{n}.A_{m} | COND(t_{1}, t_{2}, …, t_{n}, t_{n+1}, t_{n+2}, …, t_{n+m})}*

In the expression above *t _{1}, t_{2}, . . . ., t_{n}* are the tuples of relation and A

_{i}present the attribute of a relation on which t

_{i }ranges. COND represents a condition or predicate that must be true for every t

_{i}.

The conditional formula can be a combination of one or more conditions, that are connected via logical operators AND, OR, and NOT. The result value of this formula can be derived from their component formula F1 and F2 as follow

**(F1 AND F2**) is TRUE if the result of the formulas F1 and F2 are TRUE; else it is FALSE.**(F1 OR F2)**is TRUE if any of the formulas F1 or F2 is TRUE, it is FALSE only if both F1 and F2 are FALSE.**NOT (F1)**is TRUE if the result of the formula F1 is FALSE; it is FALSE if the result of formula F1 is TRUE.**NOT (F2)**is TRUE if the result of formula F2 is FALSE; it is FALSE if the result of formula F2 is TRUE.

### 2. Tuple Variables and Range Relation

A tuple variable is a variable that ranges over a specific relation present in the database. In a tuple relation calculus, while presenting in an expression we must provide the following information.

- We must specify a range relation for each of the tuple variables that we mention in the expression. If you do not specify a range relation for a particular tuple variable, then it will range over the relation present in the database.
- You must specify
*conditions*, to determine a particular combination of tuples. The condition then is evaluated for every possibility of combination tuples to determine the particular combination of a tuple for which condition comes out to be true. - Specify the set of attributes that you want to retrieve. In the obtained result you will find the value of these attributes for each combination of tuples.

### 3. Quantifiers in Tuple Relation Calculus

Quantifiers in the tuple relational calculus is a determiner that determines the scope of the term it is attached to. Quantifiers are of two types universal quantifier and existential quantifier.

A variable in a query is referred to as a free variable if no quantifier is attached to it. If a variable has a quantifier attached to it we refer to it as the bounded variable. Now let us discuss existential and universal quantifiers.

**Existential quantifier** is represented by the symbol ∃ and the syntax of the query with the existential quantifier can be represented as:

*∃T ε Cond (T)*

The query will succeed only if the condition turns to be true for at least some tuples in T.

**Universal quantifier** is represented by a symbol ∀ and the syntax of the query with universal quantifier can be represented as:

*∀ T ε Cond (T)*

The query will succeed only if the condition comes out to be true for all the tuples in T.

### 4. Safe Expression

In tuple relational calculus, an expression producing a finite number of tuples as a result we refer to it as a safe expression. Sometimes it may happen that an expression may yield infinite tuples, this expression is referred to as an unsafe expression. Consider an expression given below.

*{t| ¬ (t **∈** instructor)}*

This expression would yield infinite tuples as there would be many tuples present in the database which does not belong to *instructor* relation. So, we would consider it an unsafe expression.

To define a safe expression we must specify the **domain** of the tuple relational formula P. The domain of P can be expressed as *dom(*P*)* and it includes set all the values that are referenced by formula P*. *So we can conclude that the expression *{t| ¬ (t **∈** instructor)}* is an unsafe expression.

So, this is all about a tuple relation calculus which determines all the tuples that satisfy the provided conditions. With tuple relation calculus you can not express aggregation, grouping and ordering in the queries.

## Leave a Reply