../relational-algebra

Relational Algebra

Table of contents

Fundamental Operator

  1. Select (σ)
  2. Project (π)
  3. Union (U)
  4. Set Difference (-)
  5. Cartesian Product (X)
  6. Rename (ρ)

Select (σ)

Project (π)

Union (U)

  1. R and S must be of same arity.(no of R colums = no of S colums )
  2. For all i,Domain of the ith attribute of R = Domain of ith attribute of S.

Example - University Database

```
Instructor (ID, Name, Dept_Name, Salary)
Course (Course_ID, Title, Dept_Name, Credits)
Department (Dept-Name, Building, Budget)
Section (Course_ID, Sec_ID, Semester, Year, Building, Room_No, Time_slot_ID)
Teaches (ID, Course_ID, Sec_ID, Semester, Year)
Student (ID, Name, Dept_Name, Tot_Cred)
Advisor (S_ID, I_ID)
Takes (ID, Course_ID, Sec_ID, Semester, Year, Grade)
Classroom (Building, Room Number, Capacity)
Time Slot (Time Slot_ID, Day, Start-Time, End-Time)

```

Set Difference (-)

Two important conditions For R - S to be valid,

  1. R and S must be of same arity.

  2. For all i, Domain of the ith attribute auf R = Domain of ith attribute of S.

Cartesian Product (X)

Cartesian product associates every tuple of R, with every tuple of R2.

Rename (ρ)

Relations in the database have names.

Additional operations:

Set Intersection (∩)

The intersection operation returns the set of all tuples that are present in both relations.

Two important conditions For R ∩ S to be valid,

  1. R and S must be of same arity.(no of R colums = no of S colums )
  2. For all i,Domain of the ith attribute of R = Domain of ith attribute of S.

Assignment Operation (=)

The assignment operation allows storing the result of a relational algebra expression in a temporary relation variable.

Natural Join (⋈)

A natural join is a type of join operation in relational databases that automatically combines tables based on all columns with the same name and datatype in both tables.

Inner join

An inner join is a fundamental relational database operation that combines rows from two tables based on a related column between them.

Division Operation (÷)

Outer Join

Left Outer Join (⟕)

Returns all rows from the left table, and the matched rows from the right table

Right Outer Join (⟖)

Returns all rows from the right table, and the matched rows from the left table

Full Outer Join (⟗)

Returns all rows when there is a match in either left or right table.