You are on page 1of 5

TERM PAPER 1

DATABASE MANAGEMENT SYSTEM


CS 601
DEPARTMENT : COMPUTER SCIENCE AND
ENGINEERING
SEMESTER – 6TH
YEAR – 3RD
NAME : NIVEDITA BHAKAT
COLLEGE ROLL NUMBER : 82
UNIVERSITY ROLL NUMBER : 16900116082
UNIVERSITY REG. NO. : 161690110054 of 2016-2017
Topic- Relational Algebra and it’s applications in Database
Management System
Abstract
Relational algebra is a procedural query languages, which takes instances of relation as input
and yields instances of relations as output. It uses operators to compute the queries. An
operator can either be unary(if the operator operates on one relation) or binary(if the operator
operates on pair of relations). It consists of sets of operations to compute results of the
queries. Some of the operations are: select, project, rename, union, set intersection, set
difference.

Introduction
The select, project and rename operations are called unary operations because they operate on
one relation. The other three operations- union, set intersection and set difference operates on
pair of relations, so they are called binary operations. The select operation (σ) selects tuples
that satisfy a given predicate. It is denoted by the Greek letter sigma. The project operation
is a unary operations that returns its argument relation with certain attributes left out.
Projection is denoted by the Greek letter pi (∏). The rename operation is useful as it gives
name to the results of relational algebra expressions. Rename operator is denoted by the
Greek letter rho (ρ). The union operation allows us to find all the tuples present in both the
relations provided they must have same number of attributes and the domain of ith attribute
of both the relation must be same. Union operator is denoted by ‘U’. The set difference
operation allows us to find tuples that are present in one relation but not in another and is
denoted by ‘-’. The set intersection operation allows us to find the tuples that are present in
both the relations. The intersection operator is denoted by ‘∩’ .
r ∩ s = r - ( r - s)
Relational Algebra has vast applications:
1. It is used as a basis for implementing and optimizing queries in the query processing
and optimization modules that are integral parts of relational database management
systems.
2. It provides a formal foundation for relational model operations.
3. Some of its concepts are incorporated into the SQL standard query language for
RDBMSs.

Methodology
The Cartesian product (x) operation allows us to combine information from any two
relations. It is denoted by cross (x) symbol.
The natural join (⋈) is a binary operation that allows us to combine certain selections and a
Cartesian product into one operation. It is denoted by the join symbol ⋈. The natural join
operation forms a Cartesian product of its two arguments, performs a selection forcing
equality on those attributes that appear in both relation schemas and finally removes duplicate
attributes.
The theta join (θ) is also a binary operation. It is basically an extension to the natural join
operation that allows us to combine a selection and a Cartesian product into a single
operation. It is denoted by join symbol along with the select condition.
Equijoin (⋈) is a special case of conditional join where only equality condition holds
between a pair of attributes. As values of two attributes will be equal in result of equijoin,
only one attribute will be appeared in result.

The division operation (÷) is suited to queries that includes the phrase “for all”. It is denoted
by the division operator. It is binary operation so it contains two tables for computation. In
case of division operation numerator table must have two attributes and the denominator table
must have one attribute and there one attribute of both the table must be common.
Aggregate functions takes a collection of values and return a single value as a result. For
example, the aggregate function sum takes a collection of values and returns the sum of the
values. Thus, the function sum is applied on the collection {1,1,3,4,4,11} returns the results
as 24. The aggregate function avg returns the average of the values. When applied to the
above collection, it returns the result as 4. The aggregate function count returns the number
of elements in the collection, and returns the results as 6 when applied to the above
collection. Other common aggregate functions include min and max, which return the
minimum and maximum values in a collection. When applied to the above collection, it
returns the result as 1 and 11 respectively.
The collections on which aggregate functions operate can have multiple occurrences of a
value; the order in which the values appear is not relevant. Such collections are called
multisets. Sets are a special case of multisets where there is only one copy of each element.
There are cases where we must eliminate multiple occurrences of a value before computing
an aggregate function. If we do want to eliminate duplicates, we use the same function names
as before, with the addition of the hyphenated string “distinct” appended to the end of the
function name. The tuples in the result of expression are partitioned into groups in such a way
that
1. All tuples in a group have the same values.
2. Tuples in a different groups have different values.
The outer join operation is an extension of the join operation to deal with missing
information. We can use the outer join operation to avoid loss of information. There are
actually three forms of the operation:
A) Left outer join
B) Right outer join
C) Full outer join
The left outer join (⟕) takes all tuples in the left relation that did not match with any tuple
in the right relation, pads the tuples with null values for all other attributes from the right
relation, and adds them to the result of the natural join. All the information from the left
relation is present in the result of the left outer join.
The right outer join (⟖) is symmetric with the left outer join: It pads tuples from the right
relation that did not match with any tuple in the left relation with nulls and adds them to the
result of the natural join. All the information from the right relation is present in the result of
the right outer join.
The full outer join (⟗) does both of those operations, padding tuples from the left relation
that did not match any from the right relation, as well as tuples from the right relation that did
not match any from the left relation, and adding them to the result of the join.
For example : Consider the following relations:
Customer(cid, cname, ccity)
Order(ono, odate, cid, amount)
Order_item(ono, ino, quantity)
Shipment(ono, warehouse_no, ship_date)
Warehouse(warehouse_no, city)
Item(ino, unit_price)
1) List order no. and ship date for all orders shipped from warehouse no. W2
R ∏ ono, ship_date ( σ (warehouse_no=’W2’) (Shipment))

2) List the warehouse info from which the customer named Shyam was shipped his
orders.
R1 σ (cname=’Shyam’) (Customer ⋈ Order)
R2 (R1 ⋈ Shipment)
R ∏ warehouse_no,city (R2 ⋈ Warehouse)

3) Produce a list containing customer name, no_of_orders, avg_order_amt, where middle


column is total no. of order by the customer and last column is avg_order_amt for that
customer.
R1 cid G (sum(quantity) as no_of_orders , avg(amount) as avg_order_amt) (Order_item ⋈ Order)
R ∏ cname ,no_of_orders, avg_order_amt (Customer ⋈ R1)

4) List the orders that were not shipped within 30 days of ordering.
R ∏ ono, odate, eid, amount ( σ (ship_date>30) (Order ⋈ Shipment))

5) List orders no. for orders that were shipped from all warehouse located in
Bhubaneswar.
R1 ∏ ono, warehouse_no (Shipment)
R2 ∏ warehouse_no ( σ (city=’Bhubaneswar’) (Warehouse))
R R1 ÷ R2
Conclusion
Relational Algebra is a procedural language which provides a formal foundation for relational
model operations. Relational Algebra is often considered to be an integral part of the
relational data model.
Set operations from mathematical set theory are applicable because each relation is defined to
be a set of tuples in the formal relational model and include UNION, INTERSECTION,
SET DIFFERENCE and CARTESIAN PRODUCT (also known as CROSS PRODUCT).

Operations developed specifically for relational databases—these include SELECT,


PROJECT and JOIN among others.

REFERENCES
Database System Concepts: Abraham Silberschatz, Henry F. Korth, S. Sudarshan (5th
Edition)

You might also like