Wednesday, 13 April 2022

Relational Calculus (TRC and DRC)

Relational calculus is a non-procedural query language. In the non-procedural query language, the user is concerned with the details of how to obtain the end results. 

The relational calculus tells what to do but never explains how to do.

Types of Relational calculus:

1. Tuple Relational Calculus
2. Domain Relational Calculus

1.Tuple Relational Calculus

  1. The tuple relational calculus is specified to select the tuples in a relation. In TRC, filtering variable uses the tuples of a relation.
  2. The result of the relation can have one or more tuples.
  3. In this form of relational calculus, we define a tuple variable, specify the table(relation) name in which the tuple is to be searched for, along with a condition.
  4. We can also specify column name using a . dot operator, with the tuple variable to only get a certain attribute(column) in result.
  5. A tuple variable is nothing but a name, can be anything, generally we use a single alphabet for this, so let's say T is a tuple variable.
  6. To specify the name of the relation (table) in which we want to look for data, we do the following:
  7. Relation (T), where T is our tuple variable.

For example if our table is Student, we would put it as Student(T)


1. {T | P (T)} or {T | Condition (T)}


T is the resulting tuples

P(T) is the condition used to fetch T.

For example:

1. { | Author(T) AND T.article = 'database' }

OUTPUT: This query selects the tuples from the AUTHOR relation. It returns a tuple with 'name' from Author who has written an article on 'database'.

TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃) and Universal Quantifiers (∀).

For example:

2. { R| ∃T ∈ Authors(T.article='database' AND}

Output: This query will yield the same result as the previous one.

Domain Relational Calculus (DRC)

  1. The second form of relation is known as Domain relational calculus. In domain relational calculus, filtering variable uses the domain of attributes.
  2. Domain relational calculus uses the same operators as tuple calculus. It uses logical connectives ∧ (and), ∨ (or) and ┓ (not).
  3. It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.

1. { a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}


a1, a2 are attributes

P stands for formula built by inner attributes

For example:

1. {< article, page, subject > | ∈ computers ∧ subject = 'database'}

Output: This query will yield the article, page, and subject from the relational computers, where the subject is a database.


Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

python tutorial


C Programming


Java Tutorial


Data Structures


MS Office


Database Management