Module 2 Part2
Module 2 Part2
PART 2
SYLLABUS
• Structure of Relational Databases - Integrity
Constraints, Synthesizing ER diagram to
relational schema
• Introduction to Relational Algebra - select,
project, cartesian product operations, join -
Equi-join, natural join. Query examples
• Introduction to Structured Query Language
(SQL), Data Definition Language (DDL), Table
definitions and operations – CREATE, DROP,
ALTER, INSERT, DELETE, UPDATE.
Introduction to Relational Algebra
• Select
• Project
• Rename
• Cartesian product operations
• Join - Equi-join
• Natural join
• Query examples
Relational algebra
• Relational algebra is a procedural query
language, which takes instances of relations as
input and yields instances of relations as output.
• It uses operators to perform queries. An
operator can be either unary or binary.
• They accept relations as their input and yield
relations as their output.
• Relational algebra is performed recursively on a
relation and intermediate results are also
considered as relations.
Unary Relational Operations:
1. SELECT
2. PROJECT
3. RENAME
SELECT Operation
• The SELECT operation is used to choose a subset of
the tuples from a relation that satisfies a selection
condition.
• Horizontal partition of the relation into two sets
of tuples.
• Those tuples that satisfy the condition are
selected, and those tuples that do not satisfy the
condition are discarded.
• The SELECT operation is denoted by
(b) STUDENT ∪
INSTRUCTOR
▫ Next, create a relation that includes a tuple <Pno, Essn> whenever the
employee whose Ssn is Essn works on the project whose number is Pno
in the intermediate relation SSN_PNOS:
• Finally, apply the DIVISION operation to the
two relations, which gives the desired
employees’ Social Security numbers:
AGGREGATE FUNCTIONS & GROUPING
• Used to specify mathematical functions:
• SUM
• AVERAGE
• MAXIMUM
• MINIMUM
• COUNT
AGGREGATE FUNCTIONS & GROUPING
• Example: To find the total number of employees and their average
salary: