DBMS Menu


Tuple Relational Calculus in DBMS




Relational calculus is a Declarative Langauge or non-procedural query language.

Before understanding Relational calculus in DBMS, we need to understand Procedural Language and Declarative Langauge.

Procedural Language - Those Languages which clearly define how to get the required results from the Database are called Procedural Language. Relational algebra is a Procedural Language.

Declarative Language - Those Language that only cares about What to get from the database without getting into how to get the results are called Declarative Language. Relational Calculus is a Declarative Language.


Relational Calculus in database management system (DBMS) is all about "What you want ?". Relational calculus does not tell us how to get the results from the Database, but it just cares about what we want.

Types of Relational Calculus in DBMS

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

Tuple Relational Calculus (TRC)

Tuple Relational Calculus uses a tuple variable (t) that goes to each row of the table and checks if the predicate condition is true or false for the given row. Depending on the given predicate condition, it returns the row or part of the row.

A tuple relational calculus query has the form

Syntax
{t | P(t)}

where t is a tuple variable and P(t) is a logical formula that describes the conditions that the tuples in the result must satisfy. The curly braces {} are used to indicate that the expression is a set of tuples.

P(t) may have various conditions logically combined with OR (∨), AND (∧), NOT(¬).

It also uses quantifiers:

∃ t ∈ r (Q(t)) = ”there exists(∃)” a tuple in t in relation r such that predicate Q(t) is true.
∀ t ∈ r (Q(t)) = Q(t) is true “for all(∀)” tuples in relation r.

There are two types of tuple variables

Free Variables: Any tuple variable without any ‘For All’ or ‘there exists’ condition is called Free Variable
Bounded Variables: Any tuple variable with the ‘For All’ or ‘there exists’ condition is called Bounded Variable

Example: Retrieve the name of the students whose age is < 18
T.name | Student(T) AND T.age < 18 

Domain Relational Calculus (DRC)

Domain Relational Calculus uses domain Variables to get the column values required from the database based on the predicate expression or condition.

The key idea of Domain Relational Calculus is to define queries in terms of the domains (sets of values) of the attributes, rather than the tuples or records. Queries are formulated as expressions involving variables that range over domains.

A Domain Relational Calculus query has the form

Syntax
{<x1,x2,x3,x4...> | P(x1,x2,x3,x4...)} 

where each Xi is either a domain variable or a constant, p(x1, x2, ... ,xn ) denotes a DRC formula composed of atoms.

Example: Retrieve the name and branch of the students whose age is < 18
{< name, branch > | ∈ Student ∧ age < 18} 

Next Topic :Form of basic SQL query in DBMS