0
7.3kviews
Explain Relational algebra operations with proper examples

The terms are:

(i) Set difference

(ii) Generalized Projection

(iii) Natural join

(iv) Rename

0
144views
• Set Difference

Returns all rows that are in the result of query 1 but not in the result of query.

The relations R and S must be union-compatible, and the schema of the result is defined to be identical to the schema of R.

• Syntax: (Query Expression 1) - (Query Expression 2).
• Notation : R − S Finds all the tuples that are present in R but not in S. Пauthor (Books) - Пauthor (Articles)
• Output: Provides the name of authors who have written books but not articles.
• Generalized Projection

• It extends the projection operation by allowing arithmetic functions to be used in projection list.
• Syntax: П F1,F2 … Fn (E)

Where E: relational algebra expression

$\hspace{1cm}$Fi: arithmetic expression.

• Example:

Consider the Table "Credit-info" :

Customer-name Limit Credit_Balance
abc 2000 500
xyz 500 250
pqr 700 100
mno 1500 1000

i. Find how much money a person can spend.

$Π_{Customer-name,(Limit-Credit_balance)}(Credit-info)$

iii. Natural Join A natural join returns all rows by matching values in common columns having same name and data type of columns and that column should be present in both tables.

• Example Find all employees and their department name.

In above example both tables having ‘did’ as common column so this column is called joining column based on matching of this column, tables are joined.

iv. Rename

• We are joining a table with itself in the relational algebra expression: it’s like joining two tables with the same name and the same attributes names. Therefore, some renaming is required in such queries.
• We can give alternative name to any column (attribute) or any table of query expressions using operator called as RENAME operator.
• Syntax:
• <new_name> (<input-table_name>).
• E: relational algebra expression
• ρ x (E): returns the result of expression E under the name x.
• ρ x (A1, A2, A3… An) (E): returns the result of expression E under the name x with attributes renamed to A1, A2, A3… An.