0% found this document useful (0 votes)
104 views3 pages

Unit Ii - TRC, DRC

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views3 pages

Unit Ii - TRC, DRC

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIT-II

Tuple Relational Calculus (TRC) :

A tuple relational calculus is a non-procedural query language which


specifies to select the tuples in a relation. It can select the tuples with range
of values or tuples for certain attribute values etc. The resulting relation can
have one or more tuples.

Notation:

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

-where T is resulting tuples and P(T) is a condition used to fetch T.

Example : 1

{T.Name | EMPLOYEE (T) AND T.DEPT_ID = 10}


This select all the tuples of employee name who work for Department 10.

Example : 2

{ T.name | 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 (∀).

Example : 3

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

Output: This query will yield the same result as the previous one.
2. Domain Relational Calculus (DRC) :

A domain relational calculus uses list of attribute to be selected from the


relation based on the condition. It is same as TRC, but differs by selecting
the attributes rather than selecting whole tuples.

 The second form of relation is known as Domain relational calculus. In


domain relational calculus, filtering variable uses the domain of
attributes.
 Domain relational calculus uses the same operators as tuple calculus.
It uses logical connectives ∧ (and), ∨ (or) and ┓ (not).
 It uses Existential (∃) and Universal Quantifiers (∀) to bind the
variable.

Notation :

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


-Where a1, a2, a3, … an are attributes of the relation and P is the condition.

Example : 1

{EMP_ID,EMP_NAME | ∈EMPLOYEE ∧ DEPT_ID = 10 }


select EMP_ID and EMP_NAME of employees who work for department 10.

EXAMPLE2: {< article, page, subject > | ∈ University∧ subject = 'database'}

Output: This query will yield the article, page, and subject from the relation
University, where the subject is a database.
Difference between Tuple Relational Calculus (TRC) and Domain
Relational Calculus (DRC) :

Tuple Relational Calculus Domain Relational Calculus


(TRC) (DRC)
In TRC, the variables represent
In DRS, the variables represent the
the tuples from specified
value drawn from specified domain.
relation.
A tuple is a single element of A domain is equivalent to column
relation.In database term, it is data type and any constraints on
a row. value of data.
In this filtering variable uses In this filtering is done based on the
tuple of relation. domain of attributes.
Notation : Notation :
{T | P (T)} or {T | Condition { a1, a2, a3, …, an | P (a1, a2, a3,
(T)} …, an)}
Example : Example :
{T | EMPLOYEE (T) AND { EMP_NAME, DEPTID| < EMPLOYEE
T.DEPT_ID = 10} > DEPT_ID = 10 }

Examples to Solve:

1. To find all employees whose salary is above $50,000


write the tuple calculus expression?
2. To find the first and last names of employees whose
salary is above $50,000, write the tuple calculus
expression.
3. Retrieve the birth date and address of the employee
(or employees) whose name is John B. Smith.
4. List the name and address of all employees who
work for the ‘Research’ department.

You might also like