0
6.1kviews
Explain the following relational algebra operations with proper examples

The terms are

i. Natural join

ii. Assignment

iii. Rename

iv. Set-intersection operation

v. Union

0
87views

### Natural join

Natural join is a type of inner join which is based on column having same name and same datatype present in both the tables to be joined.

Example:

### Assignment

• The assignment operation $(←)$ provides a convenient way to express complex queries
• Write query as a sequential program consisting of a series of assignments followed by an expression whose value is displayed as a result of the query
• Assignment must always be made to a temporary relation variable
• Example: compute $r ÷s$
• $temp1 ← ∏ R-S(r ), temp2 ← ∏ R-S((temp1 x s) –∏ R-S, S(r ))result = temp1 – temp2$
• The result to the right of the ←is assigned to the relation variable on the left of the

### Rename operation $( ρ )$

• Results of relational algebra are also relations but without any name.
• The rename operation allows us to rename the output relation. rename operation is denoted with small Greek letter rho ρ
• Notation: $ρ x (E)$
• Where the result of expression E is saved with name of x.

The set intersection operation

• Finds tuples in both the relations.
• It is denoted as ∩.

Example:

Borrower (customer-name, loan-number)

Depositor (customer-name, account-number)

Customer (customer-name, street-number, customer-city)

List all the customers who have both a loan and an account.

Code:

$Π$ customer-name (Borrower) $∩ Π$ customer-name (Depositor)

### Union Operation $(∪)$

• Union operation performs binary union between two given relations and is defined as
• $r ∪ s ={ t | t ∈ r or t ∈ s}$
• Notion: $r U s$
• Where r and s are either database relations or relation result set (temporary relation).
• For a union operation to be valid, the following conditions must hold:

r, s must have same number of attributes.

Attribute domains must be compatible.

Duplicate tuples are automatically eliminated.

$∏_{author}$ (Books) $∪∏_{author}$ (Articles)

Output: Projects the name of author who has either written a book or an article or both.