Explain the unary operations of algebra relations in DBMS?

Query is a question or requesting information. Query language is a language which is used to retrieve information from a database.
Query language is divided into two types −
Procedural language
Procedural language
Non-procedural language
Non-procedural language
Information is retrieved from the database by specifying the sequence of operations to be performed.
For Example − Relational algebra.
Structure Query language (SQL) is based on relational algebra.
Relational algebra consists of a set of operations that take one or two relations as an input and produces a new relation as output.
The different types of relational algebra operations are as follows −
Select operation
Select operation
Project operation
Project operation
Rename operation
Rename operation
Union operation
Union operation
Intersection operation
Intersection operation
Difference operation
Difference operation
Cartesian product operation
Cartesian product operation
Join operation
Join operation
Division operation
Division operation
Select, project, rename comes under unary operation (operate on one table).
It displays the records that satisfy a condition and is denoted by sigma (σ). It is a horizontal subset of the original relation.
The syntax for the select operation is as follows −
σcondition(table name)
Consider the student table given below −
To display all the records of student table, use the command given below −
σ(student)
To display all the records of CSE branch in student table, we can use the command mentioned below −
σbranch=cse(student)
To display all the records in student tables whose regno>2, we can use the command given below −
σRegNo>2(student)
To display the record of ECE branch section B students, use the command given below −
σbranch=ECE ^ section=B(student)
To display the records of section B CSE and IT branch, use the following command −
σSection=B ^ Branch=cse ∨ branch=IT(student)
Consider the EMPLOYEE TABLE as another example to know about selection operation −
Retrieve information about those employees whose salary is greater than 20,000.
If one condition is specified then, we get the following −
If one condition is specified then, we get the following −
σ salary > 20,000 (emp)
If more than one condition specified in the query then ( AND: ∧, OR:∨ , Not:#, equal: =, >, <, >=, <=)
If more than one condition specified in the query then ( AND: ∧, OR:∨ , Not:#, equal: =, >, <, >=, <=)
Relational operator will be used to combine the multiple conditions into a single statement.
Example − If we wish to retrieve information of those employees whose salary > 20,000 and working as the Head of the Department (HOD) and Department number is 20.
σ salary > 20,000 ^LOC=HOD ^Deptno=20(emp)
It displays the specific column of a table. It is denoted by pie (Π). It is a vertical subset of the original relation. It eliminates duplicate tuples.
The syntax of projection operation is as follows −
∏regno(student)
Consider the student table given below −
To display regno column of student table, use the following command −
∏regno(student)
To display branch, section column of student table, use the command given below −
∏branch,section(student)
To display regno, section of ECE students, use the command mentioned below −
∏regno,section(σbranch=ECE(student))
Note − Conditions can be written in select operation but not in projection operation.
Consider the employee table to know more about projection.
If no condition is specified in the query then,
If no condition is specified in the query then,
∏ empid, ename, salary, address, dno (emp)
If condition is specified then, the composition of the select and projection is as follows −
If condition is specified then, the composition of the select and projection is as follows −
∏ empid, ename, salary, address, dno (σ salary >20,00 ^ LOC = HOD ^ dno=20) (emp)
It is used to assign a new name to a relation. It is denoted by ρ (rho).
The syntax for rename operation is as follows −
ρnewname (tablename or expression)
Consider the student table given below −
The student table is renamed with newstudent with the help of the following −
ρnewstudent (student)
The names, branch columns of the student table are renamed and newbranch respectively with the help of the following command −
ρnewname,newbranch(Πname,branch( student))
Binary operations are applied on two compatible relations.
Two relations R1, R2 are to be compatible, if they are of the same degree and the domain of corresponding attributes are the same.
The Rho in DDL used for name of relation and in DML used for name of attributes.
            SQL                      Old name                   New name
Renaming can be used by three methods, which are as follows −
Changing name of the relation.
Changing name of the relation.
Changing name of the attribute.
Changing name of the attribute.
Changing both.
Changing both.