Relational Algebra 
Relational Algebra is : 
• The formal description of how a relational database operates 
• An interface to the data stored in the database itself 
• The mathematics which underpin SQL operations 
Operators in relational algebra are not necessarily the same as SQL operators, even 
if they have the same name. 
For example, the SELECT statement exists in SQL, and also exists in relational 
algebra. These two uses of SELECT are not the same. The DBMS must take whatever 
SQL statements the user types in and translate them into relational algebra 
operations before applying them to the database.
Important Terminology 
• Relation - a set of tuples. 
• Tuple - a collection of attributes which describe some real 
world entity. 
• Attribute - a real world role played by a named domain. 
• Domain - a set of atomic values. 
• Set - a mathematical definition for a collection of objects 
which contains no duplicates.
Operators -Write 
• INSERT - provides a list of attribute values for a new tuple in a relation. This 
operator is the same as SQL. 
• DELETE - provides a condition on the attributes of a relation to determine which 
tuple(s) to remove from the relation. This operator is the same as SQL. 
• MODIFY - changes the values of one or more attributes in one or more tuples of a 
relation, as identified by a condition operating on the attributes of the relation. 
This is equivalent to SQL UPDATE. 
Operators –Retrieval 
There are two groups of operations: 
• Mathematical set theory based relations: 
UNION, INTERSECTION, DIFFERENCE, and CARTESIAN PRODUCT. 
• Special database operations: 
SELECT (not the same as SQL SELECT), PROJECT, and JOIN.
Relational SELECT 
• SELECT is used to obtain a subset of the tuples of a relation that satisfy a select 
condition. 
For example, find all employees born after 1st Jan 1950: 
SELECTdob '01/JAN/1950'(employee) 
Relational PROJECT 
• The PROJECT operation is used to select a subset of the attributes of a relation 
by specifying the names of the required attributes. 
For example, to get a list of all employees surnames and employee numbers: 
PROJECTsurname,empno(employee)
• SELECT and PROJECT 
SELECT and PROJECT can be combined together. 
For example, to get a list of employee numbers for employees in 
department number 1:
JOIN Operator 
• JOIN is used to combine related tuples from two relations: 
• In its simplest form the JOIN operator is just the cross product of 
the two relations. 
• As the join becomes more complex, tuples are removed within 
the cross product to make the result of the join more meaningful. 
• JOIN allows you to evaluate a join condition between the 
attributes of the relations on which the join is undertaken. 
The notation used is 
R JOINjoin condition S
The relational model is based on the principle of relational algebra. 
Relational algebra is a collection of operators that operate on 
relations. Each operator takes one or two relations as its input and 
produces a new relation as its output. 
RESTRICT: 
The Restrict operator extracts specified tuples or rows from a given relation, based on a 
condition. 
For example, a student table has the attributes ROLL NO[ roll number], STUDNAME [ student 
name], AGE and GENDER. The condition is to extract the tuples of only those students whose 
age is more than 25. The resultant relation appears, as follows:
PROJECT : 
• The Project operator extracts specified attributes or columns 
from a given relation 
For example, if only the name and age of the students is to be 
extracted, the resultant relation appears, as follows [assume 
that the student table has only six tuples]
PRODUCT : 
The product operator builds a relation from two specified 
relations. It consists of an possible combinations of tuples, one 
from each of the two relations. 
To be product compatible, the two tables must have common attributes. 
The Product operator creates Cartesian product between the two tables.
UNION : 
• The Union operator builds a relation from tuples appearing in either or both 
of the specified relations. 
• To be union compatible, the two tables should have the same types of 
attributes [sets of columns having the same data types] 
• For example, Consider two tables A and B. 
• A contains the roll numbers and names of all students whose major 
discipline is computer science. B contains the roll numbers and names of all 
students whose major discipline is mathematics. These tables are union 
compatible because they have the same types of attributes.
Relational Calculus 
Relational algebra is a procedural language, in which user has to write the steps or 
procedure to obtain the required results but in general a user should not have to be 
concerned with the details of how to obtain information. In relational calculus user 
is not concerned with the procedure to obtain the results, he/she just tell his/her 
requirements and the output is available without knowing the method about its 
retrieval 
In relational calculus, a query is expressed as a formula consisting of a number of 
variables and an expression involving these variables. It is up to the DBMS to 
transform these nonprocedural queries into equivalent, efficient, procedural 
queries. 
The relational calculus is used to measure the selective power of relational 
languages. A language that can be used to produce any relation that can be derived 
using the relational calculus is said to be relationally complete.
Relational Calculus 
Relation calculus, which in effect means calculating with relations, is based on 
predicate calculus, which is calculating with predicates. It is a formal language used 
to symbolize logical arguments in mathematics. Propositions specifying a property 
consist of an expression that names an individual object, and another expression, 
called the predicate, that stands for the property that the individual object 
possesses. 
If for instance, p and q are propositions, we can build other propositions "not p", "p 
or q", "p and q" and so on. In predicate calculus, propositions may be built not only 
out of other propositions but also out of elements that are not themselves 
propositions. In this manner we can build a proposition that specifies a certain 
property or characteristic of an object.
Relational Calculus can be classified in two categories: 
• Tuple Oriented relational Calculus 
• Domain Oriented relational calculus 
In relational tuple calculus, the variables represent the tuples 
from specified relations; in relational domain calculus, the 
variables represent values drawn from specified domains.
Tuple Oriented Relational Calculus 
The tuple relational calculus is based on specifying a number of tuple variables. Each 
such tuple variable normally ranges over a particular database relation. This means 
that the variable may take any individual tuple from that relation as its value. 
A simple tuple relational calculus query is of the form { t I COND(t)·}, where '1' is a 
tuple variable and COND(t) is a conditional expression involving '1'. The result of such 
a query is a relation that contains all the tuples (rows) that satisfy COND(t) 
For example, 
The relational calculus query {t I BOOK(t) and t.PRICE>lOO} will get you all the books 
whose price is greater than 100. In the above example, the condition 'BOOK(t)' 
specifies that the range relation of the tuple variable '1' is BOOK. Each BOOK tuple 't' 
that satisfies the condition 't.PRICE> 100' will be retrieved. Note that 't.PRICE' 
references the attribute PRICE of the tuple variable '1'.
Domain Oriented Relational Calculus 
The domain calculus differs from the tuple calculus in the type of variables used 
in formulas. In domain calculus the variables range over single values from 
domains of attributes rather than ranging over tuples. To form a relation of 
degree 'n' for a query result, we must have 'n' of these domain variables-one for 
each attribute. 
An expression of the domain calculus is of the following form: 
• {Xl, X2, ... , Xn I COND(XI, X2, .. ·, Xn, Xn+b Xn+2, , Xn+m)} 
In the above expression Xl, X2, ... , Xn, Xn+b Xn+2, , Xn+m are domain variables 
that range over domains of attributes and COND is a condition or formula of the 
domain relational calculus.
Expression of the domain calculus are constructed from the following 
elements: 
Domain variables Xl, X2, ... , Xn, Xn+b Xn+2, ... , Xn+m each domain variable is 
to range over some specified domain . 
• Conditions, which can take two forms: 
• Simple comparisons of the form x * y, as for the tuple calculus, except that x and yare now domain variables. 
• Membership conditions, of the form R (term, 
term ...). 
Here, R is a relation, and each "term" is a pair AV, where A in turn is an attribute 
Of R and V is either a domain variable or a constant. 
For example EMP (empno: 100, ename: 'Ajay') is a membership condition (which evaluates to 
true if and only if there exists an EMP tuple having empno=100 and ename = 'Ajay') .

Relational algebra calculus

  • 1.
    Relational Algebra RelationalAlgebra is : • The formal description of how a relational database operates • An interface to the data stored in the database itself • The mathematics which underpin SQL operations Operators in relational algebra are not necessarily the same as SQL operators, even if they have the same name. For example, the SELECT statement exists in SQL, and also exists in relational algebra. These two uses of SELECT are not the same. The DBMS must take whatever SQL statements the user types in and translate them into relational algebra operations before applying them to the database.
  • 2.
    Important Terminology •Relation - a set of tuples. • Tuple - a collection of attributes which describe some real world entity. • Attribute - a real world role played by a named domain. • Domain - a set of atomic values. • Set - a mathematical definition for a collection of objects which contains no duplicates.
  • 3.
    Operators -Write •INSERT - provides a list of attribute values for a new tuple in a relation. This operator is the same as SQL. • DELETE - provides a condition on the attributes of a relation to determine which tuple(s) to remove from the relation. This operator is the same as SQL. • MODIFY - changes the values of one or more attributes in one or more tuples of a relation, as identified by a condition operating on the attributes of the relation. This is equivalent to SQL UPDATE. Operators –Retrieval There are two groups of operations: • Mathematical set theory based relations: UNION, INTERSECTION, DIFFERENCE, and CARTESIAN PRODUCT. • Special database operations: SELECT (not the same as SQL SELECT), PROJECT, and JOIN.
  • 4.
    Relational SELECT •SELECT is used to obtain a subset of the tuples of a relation that satisfy a select condition. For example, find all employees born after 1st Jan 1950: SELECTdob '01/JAN/1950'(employee) Relational PROJECT • The PROJECT operation is used to select a subset of the attributes of a relation by specifying the names of the required attributes. For example, to get a list of all employees surnames and employee numbers: PROJECTsurname,empno(employee)
  • 5.
    • SELECT andPROJECT SELECT and PROJECT can be combined together. For example, to get a list of employee numbers for employees in department number 1:
  • 6.
    JOIN Operator •JOIN is used to combine related tuples from two relations: • In its simplest form the JOIN operator is just the cross product of the two relations. • As the join becomes more complex, tuples are removed within the cross product to make the result of the join more meaningful. • JOIN allows you to evaluate a join condition between the attributes of the relations on which the join is undertaken. The notation used is R JOINjoin condition S
  • 7.
    The relational modelis based on the principle of relational algebra. Relational algebra is a collection of operators that operate on relations. Each operator takes one or two relations as its input and produces a new relation as its output. RESTRICT: The Restrict operator extracts specified tuples or rows from a given relation, based on a condition. For example, a student table has the attributes ROLL NO[ roll number], STUDNAME [ student name], AGE and GENDER. The condition is to extract the tuples of only those students whose age is more than 25. The resultant relation appears, as follows:
  • 8.
    PROJECT : •The Project operator extracts specified attributes or columns from a given relation For example, if only the name and age of the students is to be extracted, the resultant relation appears, as follows [assume that the student table has only six tuples]
  • 9.
    PRODUCT : Theproduct operator builds a relation from two specified relations. It consists of an possible combinations of tuples, one from each of the two relations. To be product compatible, the two tables must have common attributes. The Product operator creates Cartesian product between the two tables.
  • 10.
    UNION : •The Union operator builds a relation from tuples appearing in either or both of the specified relations. • To be union compatible, the two tables should have the same types of attributes [sets of columns having the same data types] • For example, Consider two tables A and B. • A contains the roll numbers and names of all students whose major discipline is computer science. B contains the roll numbers and names of all students whose major discipline is mathematics. These tables are union compatible because they have the same types of attributes.
  • 11.
    Relational Calculus Relationalalgebra is a procedural language, in which user has to write the steps or procedure to obtain the required results but in general a user should not have to be concerned with the details of how to obtain information. In relational calculus user is not concerned with the procedure to obtain the results, he/she just tell his/her requirements and the output is available without knowing the method about its retrieval In relational calculus, a query is expressed as a formula consisting of a number of variables and an expression involving these variables. It is up to the DBMS to transform these nonprocedural queries into equivalent, efficient, procedural queries. The relational calculus is used to measure the selective power of relational languages. A language that can be used to produce any relation that can be derived using the relational calculus is said to be relationally complete.
  • 12.
    Relational Calculus Relationcalculus, which in effect means calculating with relations, is based on predicate calculus, which is calculating with predicates. It is a formal language used to symbolize logical arguments in mathematics. Propositions specifying a property consist of an expression that names an individual object, and another expression, called the predicate, that stands for the property that the individual object possesses. If for instance, p and q are propositions, we can build other propositions "not p", "p or q", "p and q" and so on. In predicate calculus, propositions may be built not only out of other propositions but also out of elements that are not themselves propositions. In this manner we can build a proposition that specifies a certain property or characteristic of an object.
  • 13.
    Relational Calculus canbe classified in two categories: • Tuple Oriented relational Calculus • Domain Oriented relational calculus In relational tuple calculus, the variables represent the tuples from specified relations; in relational domain calculus, the variables represent values drawn from specified domains.
  • 14.
    Tuple Oriented RelationalCalculus The tuple relational calculus is based on specifying a number of tuple variables. Each such tuple variable normally ranges over a particular database relation. This means that the variable may take any individual tuple from that relation as its value. A simple tuple relational calculus query is of the form { t I COND(t)·}, where '1' is a tuple variable and COND(t) is a conditional expression involving '1'. The result of such a query is a relation that contains all the tuples (rows) that satisfy COND(t) For example, The relational calculus query {t I BOOK(t) and t.PRICE>lOO} will get you all the books whose price is greater than 100. In the above example, the condition 'BOOK(t)' specifies that the range relation of the tuple variable '1' is BOOK. Each BOOK tuple 't' that satisfies the condition 't.PRICE> 100' will be retrieved. Note that 't.PRICE' references the attribute PRICE of the tuple variable '1'.
  • 15.
    Domain Oriented RelationalCalculus The domain calculus differs from the tuple calculus in the type of variables used in formulas. In domain calculus the variables range over single values from domains of attributes rather than ranging over tuples. To form a relation of degree 'n' for a query result, we must have 'n' of these domain variables-one for each attribute. An expression of the domain calculus is of the following form: • {Xl, X2, ... , Xn I COND(XI, X2, .. ·, Xn, Xn+b Xn+2, , Xn+m)} In the above expression Xl, X2, ... , Xn, Xn+b Xn+2, , Xn+m are domain variables that range over domains of attributes and COND is a condition or formula of the domain relational calculus.
  • 16.
    Expression of thedomain calculus are constructed from the following elements: Domain variables Xl, X2, ... , Xn, Xn+b Xn+2, ... , Xn+m each domain variable is to range over some specified domain . • Conditions, which can take two forms: • Simple comparisons of the form x * y, as for the tuple calculus, except that x and yare now domain variables. • Membership conditions, of the form R (term, term ...). Here, R is a relation, and each "term" is a pair AV, where A in turn is an attribute Of R and V is either a domain variable or a constant. For example EMP (empno: 100, ename: 'Ajay') is a membership condition (which evaluates to true if and only if there exists an EMP tuple having empno=100 and ename = 'Ajay') .