# 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:

1. Tuple relational calculus
2. 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)
1. there exists a tuple in ‘t’ (set of tuple) in relation ‘R’ such that ‘θ’ predicate condition is true.
2. Θ(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!

What's New

Top Interview Coding Problems/Challenges!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates