![]() |
The unary operations in Relational algebra are selection, projection, and rename. The select, project, and rename operators in relational algebra work on one relation only so they are called unary operators. In this article, we will discuss the unary operations in relational algebra. We will also discuss each unary operator in detail along with examples. Let’s start learning on the topic “Unary Operations in Relational Algebra”. What is Relational Algebra?Relational algebra is a procedural query processing language that provides the base of relational databases and SQL. Relational algebra has various operators like select, project, rename, cartesian product, union, intersection, set difference, joins, etc. These operators are used to form queries in relational algebra. What are Unary Operations in Relational Algebra?The operations that operate on only one relation are called unary operations in relational algebra. The three unary operations in relational algebra are: Selection Operation in Relational AlgebraThe selection operation is a unary operation that is performed on one relation. The selection operation is used to retrieve tuples from the relation that satisfies the given condition. It is denoted by σ. Selection operation in relational algebra is written as:
We can also add multiple conditions if required using the operators ∧ (AND), ⋁and (OR). These operators are used to combine multiple conditions as required in the problem. Below is the selection operator representation with multiple conditions.
To select all the tuples of a relation we write the selection operation without any condition.
Projection Operation in Relational AlgebraThe projection operation is a unary operation that is performed on a relation. A projection operation is used to retrieve all the values of one or more attributes. It is denoted by π. Projection operation in relational algebra is written as:
We can add multiple column names in projection operation using the comma operator if required. The comma operator is used when we have to retrieve multiple column values. Below is the projection operation representation to output multiple columns.
Rename Operation in Relational AlgebraThe rename operation is operation applied on one relation. Rename operation as the name suggests is used to rename the relation, attributes or both. It is denoted by ρ. Rename Operation for Renaming RelationRename operation for renaming relation is written as:
For example: To rename relation R to S: ρ S(R) Rename Operation for Renaming Columns of RelationRename operation for renaming columns of relation is written as:
For example: To rename columns of relation R (a, b, c) to (x, y, z): ρ (x, y, z) (R) Rename Operation for Renaming Both Relation and Columns of Given RelationRename operation for renaming both relation and columns of relation R (a, b, c) is written as:
For example: To rename both relation and columns of R (a, b, c) to S (x, y, z): ρ S (x, y, z) (R) Example on Unary Operations in Relational AlgebraExample 1: Consider the below given table and write the queries in relational algebra for the questions given below.
Q.1: Output all the tuples of the relation.
Q.2: Retrieve only those tuples where Rollno is greater than 2.
Q.3: Retrieve only those tuples where either Marks less than 70 or Studentname is A.
Q.4: Retrieve the tuples with Student Name A and Marks greater than 75.
Q.5: Output all the values in the column Rollno.
Q.6: Retrieve all the values of columns Rollno and Marks
Q.7: Retrieve the Rollno of students whose Marks is greater than or equal to 80.
Q.8: Rename the relation as S and attributes of relation Rollno as r, Studentname as Sname and Marks as m.
Example 2: Predict the output of given queries. Consider the below relation.
Q.1: Query- σ (Employee)Output:
Q.2: σSalary > 7000 ∧ Ename = P (Student)Output:
Q.3: πEname(Employee)Output:
Q.4: ρ E (id, name, S) πEid, Ename, Salary [σSalary <10000 (Employee)]Output:
ConclusionIn this article, we have discussed the unary operators that are widely used in SQL in full detail. These operators are Selection, Projection, Rename. We have also discussed the examples on all these operators for your better understanding. |
Reffered: https://www.geeksforgeeks.org
DBMS |
Related |
---|
![]() |
![]() |
![]() |
![]() |
|
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |