×

DBMS Tutorial

DBMS Practice

Relational Calculus in DBMS

DBMS | Relation Calculus: In this tutorial, we will learn about relational calculus and its types with examples. By Bharti Parmar Last updated : May 28, 2023

What is Relational Calculus?

In the database management system, the Relational Calculus is a declarative language that is used for determining the results from the database by using the predicate logic or first-order logic to determine the results from Database. Relational calculus theory was introduced by Edgar F. Codd.

types of relational calculus

Types of Relational Calculus

There is two type of relational calculus in DBMS:

  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 }



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.