DBMS Unit 3.3 (Relational Algebra)
DBMS Unit 3.3 (Relational Algebra)
3 (Relational algebra)
Relational Tuple Calculus (RTC) is a non-procedural query language used in Relational Database
Management Systems (RDBMS). It focuses on what to retrieve rather than how to retrieve it. Before
diving into actual tuple calculus expressions, you should understand the basic preliminaries or
foundational concepts:
🔹 1. Tuple Variables
A tuple variable is a variable that represents a tuple (row) from a relation (table).
🔹 2. Relations (Tables)
These are the database tables from which tuples are drawn.
less
{ t | P(t) }
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/15
Quantifiers:
Existential (`∃`): There exists a tuple…
🔹 6. Domain of Discourse
Each tuple variable ranges over a particular relation.
You must specify which relation a tuple variable belongs to using the notation like:
scss
Student(s)
🔹 7. Example Expression
Retrieve all students enrolled in course with `CourseId = 'CS101'`:
less
🔹 Summary Table
Concept Description
Tuple Variable Variable representing a row in a relation
Let me know if you want notes on Domain Relational Calculus as well, or a comparison between the
two.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/15
What is query language ? Discuss the main two types of query language used in RDMS
🔹 Key Features:
Specifies both what to retrieve and how to retrieve it.
Requires understanding of the database structure.
🔹 Example:
Relational Algebra
relational
π_name(σ_dept='CSE'(Student))
This means: Select students from 'CSE' department and project their names.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/15
2. Non-Procedural Query Language
🔹 Definition:
A non-procedural query language specifies what data is required without describing the steps to
obtain it. The system determines the best way to execute the query.
🔹 Key Features:
Focuses on what to retrieve.
Easier to use, especially for end users.
🔹 Examples:
SQL (Structured Query Language)
Relational Calculus (Tuple and Domain)
SQL Example:
sql
pgsql
✅ Comparison Table
Feature Procedural Query Language Non-Procedural Query Language
✅ Conclusion
In RDBMS, both procedural and non-procedural query languages are used. Procedural languages like
Relational Algebra are useful for understanding the underlying operations, while non-procedural
languages like SQL are more common in real-world applications due to their simplicity and abstraction.
Let me know if you'd like a visual diagram or flowchart to compare these types.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/15
What is relational algebra . Discuss the operators in detail
🔹 1. Basic Operators
a) Selection (σ)
Syntax:
php-template
σ<condition>(Relation)
Example:
bash
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 5/15
b) Projection (π)
Syntax:
php-template
π<attributes>(Relation)
Example:
scss
c) Union ( ∪ )
Syntax:
nginx
Relation1 ∪ Relation2
Example:
scss
d) Set Difference ( − )
Returns tuples in one relation that are not present in the other.
Also requires union compatibility.
Syntax:
nginx
Relation1 − Relation2
Example:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/15
scss
e) Cartesian Product ( × )
Combines each tuple of the first relation with every tuple of the second.
Syntax:
nginx
Relation1 × Relation2
Example:
nginx
Student × Course
f) Rename (ρ)
Syntax:
scss
ρ new_name (Relation)
ρ new_name(attribute1, attribute2, ...) (Relation)
Example:
scss
Syntax:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/15
nginx
R ⨝θ S
Example:
nginx
ii) Equi-Join
Syntax:
nginx
R ⋈ S
b) Intersection ( ∩ )
nginx
A ∩ B = A − (A − B)
c) Division (÷)
Returns tuples in one relation that are related to all tuples in another relation.
Example Use-Case:
Find students who have taken all courses.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/15
Operator Symbol Function
✅ Conclusion
Relational Algebra is essential for understanding how database queries are executed at a logical level. It
serves as a foundation for SQL and plays a key role in query optimization.
Let me know if you'd like examples with sample data or a diagram to visualize the operations.
🔹 Purpose of Join
To retrieve related data stored in multiple tables (relations) by matching values in common
attributes.
Outer Join (Left, Right, Full) ⟕⟖⟗ Includes unmatched rows too
Syntax:
nginx
R ⨝θ S
Procedure:
Example:
text
🔹 2. Equi-Join
Definition: A theta join with only equality ( = ) conditions.
Syntax:
nginx
R ⨝ R.A = S.B S
Procedure:
Example:
text
🔹 3. Natural Join
Definition: A special type of equi-join where the join is performed automatically on attributes with
the same name and domain.
Syntax:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/15
nginx
R ⋈ S
Procedure:
Example:
text
Joins on `DeptID`
Procedure:
2. Add remaining unmatched rows from the left with NULL for right-side values.
Syntax:
nginx
R ⟕ S
Example:
text
Employee ⟕ Department
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/15
nginx
R ⟖ S
nginx
R ⟗ S
🔹 7. Self Join
Definition: A relation is joined with itself.
Use Case: Finding relationships within the same table, like manager-employee, friends, etc.
Example:
text
🔹 8. Semi Join
Definition: Returns rows from the first relation that have matching rows in the second relation.
text
Employee ⋉ Department
🔹 9. Anti Join
Definition: Returns rows from the first relation that do not have matching rows in the second relation.
3 Carol 30
Department Table:
DeptID DeptName
10 HR
20 IT
40 Finance
Let me know if you want visual diagrams for each join or SQL equivalents.
🔹 Definition
Given two relations:
Then:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 13/15
css
A ÷ B
This means: find all `X` values in `A` that are associated with every `Y` value in B.
✅ Use Case
Used to answer “which X is related to all Y?”
Steps:
🔹 Example
Relation A: Enroll(Student, Course)
Student Course
John DBMS
John OS
Alice DBMS
Alice OS
Bob DBMS
Relation B: Course(Course)
Course
DBMS
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 14/15
Course
OS
❓ Query:
Find all students who have enrolled in all courses listed in `Course`.
✅ Solution:
nginx
Enroll ÷ Course
✅ Result:
Student
John
Alice
✅ Summary
Aspect Division Operator (`÷`)
Input A(X, Y) and B(Y)
Output Relation with attribute X
Use Case “For all” type queries
Let me know if you'd like this visualized with a Venn diagram or implemented using SQL.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 15/15