1. DDBMS
Relational Algebra Operations
Assignment Submitted To:
Miss Qurat ul Ain
Assignment Submitted By:
Shefa Idrees # 101631049
Assignment Submission Date:
07-03-2018
Department of Computer Science
2. Relational Algebra Operations
Query Language
A query language is a language in which user requests information from the database. It
can either be categorized as procedural or nonprocedural. In a procedural language the
user instructs the system to do a sequence of operations on database to compute the
desired result.
In nonprocedural language the user describes the desired information without giving a
specific procedure for obtaining that information.
Relational Algebra
The relational algebra is a procedural query language. It consists of a set of operations
that take one or two relations as input and produces a new relation as output.
The relational algebra is a relation-at-a-time (or set) language where all tuples are
controlled in one statement without the use of a loop. There are several variations of
syntax for relational algebra commands and youuse a common symbolicnotation for the
commands and present it informally.
Primary Operations of Relational Algebra
The primary operations of relational algebra are as follows:
Select (σ)
Project (∏)
Union (∪)
Set Difference (−)
Cartesian Product (Χ)
Rename (ρ)
Select Operation
Selection operator is used to select tuples from a relation based on some condition.
Notation − σp(r)
3. Where σ stands for selection predicate and r stands for relation. p is prepositional logic
formula which may use connectors like and, or, and not. These terms may use relational
operators like − =, ≠, ≥, <, >, ≤.
For example −
σsubject = "database"(Books)
Output − Selects tuples from books where subject is 'database'.
Project Operation (∏)
Projection operator is used to project particular columns from a relation.
The Projection operation works on a single relation R and defines a relation that
contains a vertical subset of R, extracting the values of specified attributes and
eliminating duplicates.
Notation − ∏A1, A2, An (r)
Where A1, A2 , An are attribute names of relation r.
Duplicate rows are automatically eliminated, as relation is a set.
For example −
∏subject, author (Books)
Output − Selects and projects columns named as subject and author from the relation
Books.
Union Operation (∪)
For R ∪ S, the union of two relations R and S defines a relation that contains all the
tuples of R, or S, or both R and S, duplicate tuples being eliminated. R and S must be
union-compatible.
For a union operation to be applied, the following rules must hold −
R and S must have the same quantity of attributes.
4. Attribute domains must be compatible.
Duplicate tuples get automatically eliminated.
Notation − r U s
For example −
∏ author (Books) − ∏ author (Articles)
Output − Projects the names of the authors who have either written a book or an article
or both.
Set Difference Operation (−)
For R – S, the Set difference operation defines a relation consisting of the tuples that are
in relation R, but not in S. R and S must be union-compatible.
Notation − r – s
For example −
∏ author (Books) − ∏ author (Articles)
Output − Provides the name of authors who have written books but not articles.
Cartesian Product (Χ)
For R × S, the Cartesian product operation defines a relation that is the concatenation of
every tuple of relation R with every tuple of relation S.
Notation − r Χ s
For example −
σauthor= 'tutorialspoint'(Books Χ Articles)
Output − Yields a relation, which shows all the books and articles written by
tutorialspoint.
5. Rename Operation (ρ)
The results of relational algebra are also relations but without any name. The rename
operation provides database designers to rename the output relation. The rename-
operation is denoted using small Greek letter rho (ρ).
Notation − ρ x (E)