Modification of the Database in Relational Algebra

Antosh Dyade November 09, 2022

  • Different operations that modify the contents of the database are​
    • Delete​
    • Insert​
    • Update​
  • We express database modification by using the assignment operation.​

Deletion

  • The deletion operation removes the selected tuples from the database using delete values of any particular attribute.​
  • In relational algebra a deletion is expressed by​
    •  r ← r - E​
    •  r is a relation​
    • E is a relational algebra query​

Example
Delete 'Ramesh' Record from the database​
    • employees ← employees - σemp_name='Ramesh'(employees)
  • Delete all employee working in IT department​
    • employees ← employees - σdepartment='IT'(employees)

Insertion

  • The relational algebra expresses an insertion by ​
    • r ← r Ս E​
    • r is a relation​
  • E is relational algebra expression​

Examples​
  • Insert Ramesh Record in employee relation​
    • employees ← employees Ս {('E004','Ramesh', 12000)}​

Updating

  • Sometimes, we wish to change a value in a tuple without changing all values in the tuple. We can use generalized projection operation to do this:​
    • r  ← ∏f1,f2,f3...fn(r)
      • Where fi the ith attribute to be updated has expression involving constants and attributes of r, that gives new value for the attribute. ​
  • Example​
    • emp_id, salary*1.05(employees)

Share this

Related Posts

Previous
Next Post »