National Institute of Technology K arnataka S urath kal
Department of Information Technology
IT 252 DATABASE SYSTEMS
The Relational Algebra and Relational
Calculus
Dr. Jayashree T R
Course Outline
Course Plan: Theory:
Part A: Parallel Computer Architectures
Week 1: Introduction to to the course, highlighting the data and databases, and related basic
concepts. Advantages and need for a database system.
Week 2: Attributes, tuples, relational schema, conceptual model, introduction to SQL-DML, DDL,
creating relations/ tables, access and manipulate data.
Week 3,4: Data model, relational model, and SQL, relational data model and relational database
constraints, SQL data definition and data types, specifying constraints, basic retrieval queries, complex
quires, triggers, views, schema modification.
Week 5-6: ER model development, entity types/sets, attribute, relationship types/sets, simple employee
database conceptual design using ER concepts, ER to relational mapping algorithm, EER model.
Course Outline
Functional dependency definition, need of normalization, anomalies and
Week 7,8 : redundant information in tuples, normalization steps (INF, 2NF, 3NF),
BCNF, introduction to the higher normal forms.
Week 9: Procedural query languages: relational algebra and SQL-SELECT, PROJECT, RENAME, binary
and JOIN operations with examples.
Non-Procedural query languages: relational calculus, and SQL-tuple relational calculus, existential a
universal quantifier with examples.
Week 10,11 : Transaction management, schedule and serializability, concurrency control, 2-phase lock,
recovery mechanism: undo/redo values.
Week 1 2 , 1 3 : Disk storage- basic file structures, ordered/unordered. binary search, hashing, indexing,
importance of indexes, primary and secondary indexing methods, clustered, B tree, B++ trees.
Week 1 4 : Current trends in database system, introduction to data warehousing, data mining.
Practical: MySQL commands
Project: Team of 2 or 3 members
The Relational Algebra and Relational Calculus
• The RELATIONAL ALGEBRA and the RELATIONAL CALCULUS FORMAL
LANGUAGES
• SQL standard PRACTICAL LANGUAGE
• The relational algebra and calculus were developed before the SQL language.
SQL is primarily based on concepts from relational calculus and has been extended
to incorporate some concepts from relational algebra as well.
• RELATIONAL ALGEBRA is the basis for SEQUEL (Structured English Query
Language), later shortened to SQL.
Consider the relation STUDENT:
Now, if you apply the projection operator to select the Name column from the
π
relation, ( Name (STUDENT):
STUDENT
Appears only once in the result of
projection operation.
Projection eliminates duplicates because a relation in relational algebra is
considered a set of tuples, and sets do not allow duplicate elements.
Can you compare the Projection operation with the SELECT
statement of MySQL?
How does the SELECT statement eliminates duplicates ?
Automatically or not?
Example of applying SELECT OPERATION:
For example, to list each employee’s first and last name and salary, we can use the
PROJECT operation as follows:
π Lname, Fname, Salary(EMPLOYEE)
Consider the following PROJECT operation:
Π Sex, Salary(EMPLOYEE)
appears only once, duplicates are
eliminated.
𝜋 𝐴,𝐵(𝜋𝐴(𝑅)) ≠ 𝜋𝐴(𝜋 𝐴,𝐵(𝑅))
The select operation (σ) eliminates duplicates because operations are based
on set theory, and sets do not allow duplicate elements.
Employees
EmployeeID Name Age
1 Alice 30
2 Bob 25
3 Charlie 28
1 Alice 30
select operation (σ) to find all employees with the name "Alice":
σName='Alice'(Employees)
Example of applying SELECT OPERATION:
For example, To select the tuples for all employees who either work in department 4 and make
over $25,000 per year, or work in department 5 and make over $30,000, we can specify the
following SELECT operation:
σ(Dno=4 AND Salary>25000) OR (Dno=5 AND Salary>30000)(EMPLOYEE)
In SQL, the SELECT condition is typically specified in the WHERE clause of
a query.
For example, the following operation:
σ Dno=4 AND Salary>25000 (EMPLOYEE)
would correspond to the following SQL query:
SELECT *
FROM EMPLOYEE
WHERE Dno=4 AND Salary>25000;
πFname, Lname, Salary(σDno=5(EMPLOYEE))
DEP5_EMPS ← σDno=5(EMPLOYEE)
RESULT ← πFname, Lname, Salary(DEP5_EMPS)
TEMP ← σDno=5(EMPLOYEE)
R(First_name, Last_name, Salary) ← πFname, Lname, Salary(TEMP)
In relational algebra, the division operator (denoted as ÷) is used to find tuples in
one relation (table) that are associated with all tuples in another relation.
e.g. We want to find the SSNs of employees who are assigned to all the
projects that Smith is assigned to.
• a list of all the projects that Smith is assigned to.
• need to find employees who are assigned to every one of those projects.
i.e. By dividing the employees' project assignments by the projects Smith is
assigned to, we can get those employees who meet the required condition.
Find the SSNs of employees who are
assigned to all the projects that Smith is
assigned to.
This can be expressed in relational algebra
as:
πSSN (SSN_PNOS ÷ SMITH_PNOS)
Note: The symbol ℱ is
called the script letter
F or calligraphic F. It's
often used in
mathematics,
particularly in set
theory, functional
analysis, and
relational algebra, to
represent functions,
operators, or specific
mathematical
concepts.
Examples of Queries in Relational Algebra
Examples of Queries in Relational Algebra
Examples of Queries in Relational Algebra
Examples of Queries in Relational Algebra
Relational Calculus
• Predicate Calculus, also known as First-Order Logic (FOL), is a formal system used
in mathematics, logic, and computer science to express statements about objects
and their relationships. It extends propositional logic by introducing
quantifiers and predicates, allowing for more complex expressions.
• In mathematics, a predicate is a statement or assertion containing one or more
variables, whose truth value depends on the values of those variables.
• e.g.: "x is greater than 5". This is a predicate because its truth depends on the
value of 'x'. If x = 6, the statement is true, but if x = 3, it's false.
• In mathematical logic, quantifiers are words or symbols that specify the quantity
or number of elements a statement applies to, either "for all" (universal
quantifier) or "there exists" (existential quantifier).
• Universal Quantifier (∀): Represents "for all" or "for every". It asserts that a
property holds true for every element in a given set or domain.
• Existential Quantifier (∃): Represents "there exists" or "there is at least
one". It asserts that at least one element in a given set or domain satisfies a
particular property.
Practice Questions
Practice Questions
Practice Questions
Practice Questions
Practice Questions
Practice Questions
Practice Questions
Practice Questions : solve by yourself. Solutions given here may not be correct.
Practice Questions
Practice Questions
THANK YOU