You are on page 1of 11

Relational Algebra

Domain: set of relations Basic operators: select, project, union, set difference, select project union difference Cartesian product Derived operators: set intersection, division, join intersection division Procedural: Relational expression specifies query by describing an algorithm (the sequence in which operators are applied) for determining the result of an expression

What is an Algebra
Mathematical system consisting of:
Operands --- variables or values from which new values can be constructed. Operators --- symbols denoting procedures that construct new values from given values.

What is Relational Algebra?


An algebra whose operands are relations or variables that represent relations. Operators are designed to do the most common things that we need to do with relations in a database.
The result is an algebra that can be used as a query language for relations.
3

Core Relational Algebra


Union, intersection, and difference.
Usual set operations, but require both operands have the same relation schema.

Selection: picking certain rows. Projection: picking certain columns. Products and joins: compositions of relations. Renaming of relations and attributes.
4

Selection Condition
Operators: <, , , >, =, Simple selection condition:
<attribute> operator <constant> <attribute> operator <attribute>

<condition> AND <condition> <condition> OR <condition> NOT <condition>


5

Relational Algebra
Basic Set Oriented Operations Union U Intersection I Set Difference Cartesian Relational Oriented Operations Selection Projection

Join Division

Table Name: EMP


EmP_IdEmp_Name Salary

Query's
Display Emp_name, Salary from EMP Display the Salary More than 1200

101 102 103 104 105

Bipin Desai Korth Sudarshan Raman

1000 1200 1234 2345 1567


LOC Hyd Delhi Mumbai

In Relational Algebra

Table Name: DEPT


Dept No DName 10 20 30 Marketing Sales Accounting

( EmP Name , Salary )

Sigma Operator used for Select Purpose ( Employee)

( Salary >1200) ( Employee)


In SQL
SQL> Select Emp_name, Salary from EMP; SQL> Select Emp_name, Salary from EMP

Examples on Selection Condition


Emp_id > 102 Or Salary=1200 (Employee) Emp_Id > 102
AND Emp_Id <107

(Employee)

NOT(Dname=Computer science) (Dept) Dname Computer science (Dept)

You might also like