# Relational Calculus in DBMS

## Relational Calculus in DBMS

In this article, we will learn about Relational Calculus in DBMS. Using a non procedural query language, unlike the procedural one used in relational algebra. In other words it only provides the information about description of the query but not detailed methods on how to do it.

#### What is Relational Calculus?

Using a non procedural query language, unlike the procedural one used in relational algebra. In other words it only provides the information about description of the query but not detailed methods on how to do it.

• Relational Calculus focusses upon mathematical predicate calculus
• Relational Algebra focusses on mathematic algebra

Forms of relational Calculus –

1. Tuple Relational Calculus (TRC)
2. Domain Relational Calculus (DRC)

### Tuple Relational Calculus (TRC)

1. In tuple calculus we find tuples which are true for a given condition.
2. The predicate must be true for a tuple
3. Result obtained maybe more than 1 tuple.

Use – For relational calculus.

Notation – `{t| P(t)}`

Breakdown –

1. `t` represents tuples returned as results
2. `P` for Predicate i.e. conditions for results​

Other relevant notations –

• `∈` – represents Belongs to
• `∃` – called an existential quantifier represents there is at least one
• `r` – means relation
• `(∨)` – OR
• `(∧)` – AND
• `(¬)` – NOT

Example 1 :

`{t | Employee (e) and e.SALARY > 100000}`
• Now, this represents results which will be returned as `tuple t.`
• Predicate here is – `Employee (e) and e.SALARY > 100000`
• Will return tuples for all the employees which have salary greater than 100000.

We can also write this as –

`{t | t ∈ Employee (e) and e.SALARY > 100000}`

This just represents that the tuple t belongs to relation Employee and we’re using this to be on the safe side.

Example 2 :

`{t| ∃ s ∈ Salary(t.emp_ID = s.emp_ID ∧ s.Salary >= 100000)}`

It will result in the emp_Id for each employee that has his/her salary  greater or equal to 10000.

### Domain Relational Calculus (DRC)

While in tuple relationship calculus we did relational mathematics based on the tuple results and predicates. In domain relational calculus, however, we do it based on the domains of the attributes.

Use – For relational calculus.

Notation – `{ c1, c2, ..., cn | F(c1, c2, ... ,cn)}`

Breakdown –

1. `c1, c2, ..., cn` represents domain of attributes(columns)
2. `F `for Predicate i.e. condition for results​

Example :

`{< Fname, Emp_ID > | ∈ Employee ∧ Salary > 10000}`

The result here will be returning the Fname and Emp_ID values for all the rows in the employee table where salary is greater than 10000.

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others