Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE) PDF Download

Introduction

Relational Algebra is a procedural query language which takes relations as an input and returns relation as an output. There are some basic operators which can be applied on relations to produce required results which we will discuss one by one. We will use STUDENT_SPORTS, EMPLOYEE and STUDENT relations as given in Table 1, Table 2 and Table 3 respectively to understand the various operators.

Table 1: STUDENT_SPORTSTable 1: STUDENT_SPORTS

Table 2: EMPLOYEETable 2: EMPLOYEE

Table 3: STUDENTTable 3: STUDENT

  1. Selection operator (σ): Selection operator is used to select tuples from a relation based on some condition.
    Syntax:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Extract students whose age is greater than 18 from STUDENT relation given in Table 1Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  2. Projection Operator (∏): Projection operator is used to project particular columns from a relation.
    Syntax:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Extract ROLL_NO and NAME from STUDENT relation given in Table 3Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Note: If resultant relation after projection has duplicate rows, it will be removed. For Example: ∏(ADDRESS)(STUDENT) will remove one duplicate row with value DELHI and return three rows.
  3. Cross Product(X): Cross product is used to join two relations. For every row of Relation1, each row of Relation2 is concatenated. If Relation1 has m tuples and and Relation2 has n tuples, cross product of Relation1 and Relation2 will have m X n tuples.
    Syntax:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)To apply Cross Product on STUDENT relation given in Table 1 and STUDENT_SPORTS relation given in Table 2,Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  4. Union (U): Union on two relations R1 and R2 can only be computed if R1 and R2 are union compatible (These two relation should have same number of attributes and corresponding attributes in two relations have same domain) . Union operator when applied on two relations R1 and R2 will give a relation with tuples which are either in R1 or in R2. The tuples which are in both R1 and R2 will appear only once in result relation.
    Syntax:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Find person who are either student or employee, we can use Union operator like:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  5. Minus (-): Minus on two relations R1 and R2 can only be computed if R1 and R2 are union compatible. Minus operator when applied on two relations as R1-R2 will give a relation with tuples which are in R1 but not in R2.
    Syntax:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Find person who are student but not employee, we can use minus operator like:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  6. Rename(ρ): Rename operator is used to give another name to a relation.
    Syntax:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)To rename STUDENT relation to STUDENT1, we can use rename operator like:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)If you want to create a relation STUDENT_NAMES with ROLL_NO and NAME from STUDENT, it can be done using rename operator as:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)


Extended Operators in Relational Algebra

Extended operators are those operators which can be derived from basic operators.There are mainly three types of extended operators in Relational Algebra:

  • Join
  • Intersection
  • Divide

The relations used to understand extended operators are STUDENT, STUDENT_SPORTS, ALL_SPORTS and EMPLOYEE which are shown in Table 1, Table 2, Table 3 and Table 4 respectively.

STUDENT

Table 1 Table 1 

 STUDENT_SPORTS

Table 2 Table 2 

Table 3 Table 3 

EMPLOYEE  

 Table 4  Table 4 

  1. Intersection (∩): Intersection on two relations R1 and R2 can only be computed if R1 and R2 are union compatible (These two relation should have same number of attributes and corresponding attributes in two relations have same domain). Intersection operator when applied on two relations as R1∩R2 will give a relation with tuples which are in R1 as well as R2. Syntax:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Example: Find a person who is student as well as employee- STUDENT ∩ EMPLOYEE
    In terms of basic operators (union and minus):Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  2. Conditional Join(⋈c): Conditional Join is used when you want to join two or more relation based on some conditions. Example: Select students whose ROLL_NO is greater than EMP_NO of employeesOperators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)In terms of basic operators (cross product and selection):Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  3. Equijoin(⋈): Equijoin is a special case of conditional join where only equality condition holds between a pair of attributes. As values of two attributes will be equal in result of equijoin, only one attribute will be appeared in result.
    Example: Select students whose ROLL_NO is equal to EMP_NO of employeesOperators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)In terms of basic operators (cross product, selection and projection):
    (STUDENT.ROLL_NO, STUDENT.NAME, STUDENT.ADDRESS, STUDENT.PHONE, STUDENT.AGE EMPLOYEE.NAME, EMPLOYEE.ADDRESS, EMPLOYEE.PHONE, EMPLOYEE>AGE)(STUDENT.ROLL_NO=EMPLOYEE.EMP_NO) (STUDENT×EMPLOYEE))
    Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  4. Natural Join(⋈): It is a special case of equijoin in which equality condition hold on all attributes which have same name in relations R and S (relations on which join operation is applied). While applying natural join on two relations, there is no need to write equality condition explicitly. Natural Join will also return the similar attributes only once as their value will be same in resulting relation.
    Example: Select students whose ROLL_NO is equal to ROLL_NO of STUDENT_SPORTS as:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)In terms of basic operators (cross product, selection and projection):
    (STUDENT.ROLL_NO, STUDENT.NAME, STUDENT.ADDRESS, STUDENT.PHONE, STUDENT.AGE STUDENT_SPORTS.SPORTS)(STUDENT.ROLL_NO=STUDENT_SPORTS.ROLL_NO) (STUDENT×STUDENT_SPORTS))
    Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Natural Join is by default inner join because the tuples which does not satisfy the conditions of join does not appear in result set. e.g.; The tuple having ROLL_NO 3 in STUDENT does not match with any tuple in STUDENT_SPORTS, so it has not been a part of result set.
  5. Left Outer Join(⟕): When applying join on two relations R and S, some tuples of R or S does not appear in result set which does not satisfy the join conditions. But Left Outer Joins gives all tuples of R in the result set. The tuples of R which do not satisfy join condition will have values as NULL for attributes of S.
    Example: Select students whose ROLL_NO is greater than EMP_NO of employees and details of other students as wellOperators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  6. Right Outer Join(⟖): When applying join on two relations R and S, some tuples of R or S does not appear in result set which does not satisfy the join conditions. But Right Outer Joins gives all tuples of S in the result set. The tuples of S which do not satisfy join condition will have values as NULL for attributes of R.
    Example: Select students whose ROLL_NO is greater than EMP_NO of employees and details of other Employees as wellOperators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  7. Full Outer Join(⟗): When applying join on two relations R and S, some tuples of R or S does not appear in result set which does not satisfy the join conditions. But Full Outer Joins gives all tuples of S and all tuples of R in the result set. The tuples of S which do not satisfy join condition will have values as NULL for attributes of R and vice versa.
    Example: Select students whose ROLL_NO is greater than EMP_NO of employees and details of other Employees as well and other Students as wellOperators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)Result:Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)
  8. Division Operator (÷): Division operator A÷B can be applied if and only if:
    (i) Attributes of B is proper subset of Attributes of A.
    (ii) The relation returned by division operator will have attributes = (All attributes of A – All Attributes of B)
    (iii) The relation returned by division operator will return those tuples from relation A which are associated to every B’s tuple.

Consider the relation STUDENT_SPORTS and ALL_SPORTS given in Table 2 and Table 3 above.

To apply division operator as

Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)

  • The operation is valid as attributes in ALL_SPORTS is a proper subset of attributes in STUDENT_SPORTS.
  • The attributes in resulting relation will have attributes {ROLL_NO, SPORTS}-{SPORTS} = ROLL_NO
  • The tuples in resulting relation will have those ROLL_NO which are associated with all B’s tuple {Badminton, Cricket}. ROLL_NO 1 and 4 are associated to Badminton only. ROLL_NO 2 is associated to all tuples of B. So the resulting relation will be:

Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)

The document Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Database Management System (DBMS).
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
62 videos|66 docs|35 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Operators in Relational Algebra - Database Management System (DBMS) - Computer Science Engineering (CSE)

1. What is relational algebra and what are its operators?
Ans. Relational algebra is a procedural query language used to perform operations on relational databases. It consists of various operators such as selection, projection, union, set difference, cartesian product, join, and division.
2. How does the selection operator work in relational algebra?
Ans. The selection operator in relational algebra is used to retrieve tuples from a relation that satisfy a specified condition. It works by applying a condition or predicate to each tuple of a relation and returning only those tuples that satisfy the condition.
3. What is the difference between union and set difference operators in relational algebra?
Ans. The union operator in relational algebra combines two relations and returns a relation that contains all the tuples from both relations, eliminating duplicates. On the other hand, the set difference operator subtracts tuples from one relation that are also present in another relation, resulting in a new relation.
4. How does the join operator work in relational algebra?
Ans. The join operator in relational algebra combines two relations based on a common attribute and returns a relation that contains all the tuples from both relations where the attribute values match. It works by comparing the attribute values of each tuple in one relation with the attribute values of each tuple in another relation.
5. What is the purpose of the projection operator in relational algebra?
Ans. The projection operator in relational algebra is used to select specific attributes or columns from a relation and create a new relation that includes only those attributes. It is helpful in reducing the complexity of a relation and extracting relevant information for a particular query or analysis.
62 videos|66 docs|35 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

shortcuts and tricks

,

Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)

,

Objective type Questions

,

practice quizzes

,

pdf

,

Viva Questions

,

Free

,

Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)

,

video lectures

,

ppt

,

Important questions

,

Previous Year Questions with Solutions

,

Semester Notes

,

Sample Paper

,

Operators in Relational Algebra | Database Management System (DBMS) - Computer Science Engineering (CSE)

,

Summary

,

mock tests for examination

,

MCQs

,

Exam

,

study material

,

Extra Questions

,

past year papers

;