ASSIGNMENT
ASSIGNMENT
ASSIGNMENT
Q.6 Write a note on Relational Algebra.
Answer :-
Relational Algebra Operations are : Select, Project, Union, Intersection, and Rename
Relational algebra provides a collection of algebraic operation that operate on relations (or tables) and it gives output result in the form of tables.
Relational Algebra is a procedural query language used to manipulate and retrieve data from relational databases.
It consists of a set of operations that take one or more relations as input and produce a new relation as output.
These operations are the foundation for query processing in relational databases.
1. Select Operation (σ) :
Definition : The Select operation is used to retrieve rows (tuples) from a relation (table) that satisfy a specific condition.
Notation: σ condition(Relation)
Functionality: Filters data by applying a condition to the rows of a relation.
Example:
Let
Employeebe a table with attributesEmpID,Name, andDepartment. To retrieve employees in the “IT” department:σDepartment=′IT′(Employee)
2. Project Operation (π):
Definition: The Project operation selects specific columns (attributes) from a relation, eliminating duplicates.
Notation: π attribute1,attribute2,…(Relation)
Functionality: Reduces the number of columns in the output while preserving distinct tuples.
Example:
From the Employee table, to retrieve only the Name and Department columns:
π Name,Department(Employee)
3. Union Operation (∪)
Definition: The Union operation combines tuples from two relations and removes duplicates.
Notation: Relation1∪ Relation2
Conditions for Use: Both relations must have the same number of attributes. The attributes in both relations must have the same domain.
Example:
If
R1andR2are two tables with the same schema:R1 ∪ R2
Combines all tuples from both relations without repetition.
4. Intersection Operation (∩)
Definition: The Intersection operation returns tuples that are present in both relations.
Notation:
Relation1 ∩ Relation2
Conditions for Use: Both relations must have the same number of attributes.
The attributes in both relations must have the same domain.
Example:
If
R1andR2are two tables with the same schema:R1 ∩ R2
Retrieves tuples common to both relations.
5. Rename Operation (ρ)
Definition: The Rename operation allows a relation to be given a new name or its attributes to be renamed.
Notation: ρ NewName (Relation)
Functionality: Useful when working with multiple relations that require aliasing to avoid ambiguity.
Example:
To rename the relation
EmployeetoStaff:ρ Staff (Employee)
To rename attributes:
ρ Staff (EmpID,EmpName,Dept) (Employee)