# Relational Calculus in DBMS

In this article, we will learn **relational calculus which is known as a non-procedural language**. Relational algebra is used for focus on retrieve, declarative and to express the query.

Submitted by Bharti Parmar, on October 29, 2018

**Relational calculus uses variable, the formula for state and it has the same expressive power**. There is two type of **Relational calculus**:

- Tuple relational calculus
- Domain relational calculus

### 1) Tuple relational calculus

It is also known as predicate calculus. Tuple (t) variable range for all tuple of relation or table (R).

**t.A --> Column ‘A’ of tuple ‘t’**

**Basic form: { T | P ( T ) }** where, T is variable and P(T) is formula to fetch true tuple.

**Like: { t.A1, t.A2 … t.Ai | θ } **

where, **t.A1, t.A2 ... t.Ai** is predicate calculus expression and θ is condition.

**Let, we have a table name Student [ R.No, Name, D.No, Gender ]**

**Example: - Find R.No and Name of all student in D.No is 2.**

**{ t.R.No, t.Name | t ϵ Student (Student(t)) ^ t.D.N0 = 2 }**

Relational calculus uses variables, constant, comparison operators ( ==, >, <, >=, <=, != ), logical operators (˅ , ˄) and quantifiers ( Ǝ, ᵿ ).

**Quantifier:**

Condition is expressed by use quantifier with a tuple variable. Two type of quantifiers is there Ǝ (there exists), ᵿ (for all) .

**Like: -**

- Ǝt (variable) -> R(θ(t)) (relation and condition)
- ᵿt (variable) -> R(θ(t)) (relation and condition)

- there exists a tuple in ‘t’ (set of tuple) in relation ‘R’ such that ‘θ’ predicate condition is true.
- Θ(t) is true for all tuple in ‘t’ in relation ‘R’.

**Variable uses:** Free tuple (no quantifier use), use quantifier in bound expression.

**Example:** List all the employee name who have no manager.

**{ t.name | t ϵ emp ( Ǝ emp) ˄ manager = ‘NULL’ }**

### 2) Domain relational calculus

Domain (d (attribute)) variable range for all domain (columns) of relation or table (R). It is similar work on all the domains (columns) as tuple relational calculus work for all row.

**Basic form: { D | P ( D ) }** where, D is variable and P(D) is formula to fetch true domain.

**Like: { d.A1, d.A2 … d.Ai | θ } **

where, **d.A1, d.A2 ... d.Ai** is domain calculus expression and θ is condition.

**Let, we have a table name Student [ R.No, Name, D.No, gender ]**

**Example: -** Find R.No and Name of all student in D.No is 2.

**{ d.R.No, d.Name, d.D.No, d.gender | d ϵ Student (Student(d)) ^ d.D.N0 = 2 }**

**Conclusion**

In this article, we have learned about **what is relation calculus and its different types with example?** I hope you all clear the concept. Stay tuned for the next article, we will discuss more it in the upcoming articles. Have a nice day! Happy Learning!

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.

Learn PCB Designing: PCB DESIGNING TUTORIAL