0% found this document useful (0 votes)
59 views

Lecture Notes 11

The document discusses different relational algebra operations including Cartesian product, rename, natural join, and division. It provides examples of applying each operation to sample borrower and loan tables. Cartesian product pairs every row of one table with every row of another. Rename renames attributes to avoid confusion. Natural join performs a selection to match attribute values between tables. Division is used for "for all" queries, such as finding customers with accounts at all branches in a city.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Lecture Notes 11

The document discusses different relational algebra operations including Cartesian product, rename, natural join, and division. It provides examples of applying each operation to sample borrower and loan tables. Cartesian product pairs every row of one table with every row of another. Rename renames attributes to avoid confusion. Natural join performs a selection to match attribute values between tables. Division is used for "for all" queries, such as finding customers with accounts at all branches in a city.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lecture Notes For DBMS and Data Mining and Data Warehousing

Lecture-11 Cartesian-Product or Cross-Product (S1 R1) Each row of S1 is paired with each row of R1. Result schema has one field per field of S1 and R1, with field names `inherited if possible. Consider the borrower and loan tables as follows: Borrower:
Cust-name Ram Shyam Suleman Loan-no L-13 L-30 L-42

Loan:
Loan-no L-13 L-30 L-42 Amount 1000 20000 40000

Cross product of Borrower and Loan, Borrower Loan =


Borrower.Custname Ram Ram Ram Shyam Shyam Shyam Suleman Suleman Suleman Borrower.Loanno L-13 L-13 L-13 L-30 L-30 L-30 L-42 L-42 L-42 Loan.Loanno L-13 L-30 L-42 L-13 L-30 L-42 L-13 L-30 L-42 Loan.Amount 1000 20000 40000 1000 20000 40000 1000 20000 40000

The rename operation can be used to rename the fields to avoid confusion when two field names are same in two participating tables: For example the statement, Loan-borrower(Cust-name,Loan-No-1, Loan-No-2,Amount)( Borrower Loan) results into- A new Table named Loan-borrower is created where it has four fields which are renamed as Cust-name, Loan-No-1, Loan-No-2 and Amount and the rows contains the same data as the cross product of Borrower and Loan. Loan-borrower:
Cust-name Ram Ram Ram Shyam Shyam Shyam Suleman Suleman Suleman Loan-No-1 L-13 L-13 L-13 L-30 L-30 L-30 L-42 L-42 L-42 Loan-No-2 L-13 L-30 L-42 L-13 L-30 L-42 L-13 L-30 L-42 Amount 1000 20000 40000 1000 20000 40000 1000 20000 40000

Rename Operation: It can be used in two ways : ( ) return the result of expression E in the table named x. o

Department of Electrical and Electronics

By: Sulabh Bansal

Lecture Notes For DBMS and Data Mining and Data Warehousing

) return the result of expression E in the table named x with the attributes renamed to A1, A2,, An. o Its benefit can be understood by the solution of the query Find the largest account balance in the bank It can be solved by following steps: 1. Find out the relation of those balances which are not largest. a. Consider Cartesion product of Account with itself i.e. Account Account b. Compare the balances of first Account table with balances of second Account table in the product. c. For that we should rename one of the account table by some other name to avoid the confusion d. It can be done by following operation Account.balance (Account.balance < d.balance(Account d(Account)) e. So the above relation contains the balances which are not largest. 2. Subtract this relation from the relation containing all the balances i.e . balance (Account). 3. So the final statement for solving above query is balance (Account)- Account.balance (Account.balance < d.balance(Account d(Account)) o
(

)(

Additional Operations Natural Join ( ) Forms Cartesian product of its two arguments, performs selection forcing equality on those attributes that appear in both relations For example consider Borrower and Loan relations, the natural join between them will automatically perform the selection on the table returned by Borrower Loan which force equality on the attribute that appear in both Borrower and Loan i.e. Loan-no and also will have only one of the column named Loan-No. That means = Borrower.Loan-no = Loan.Loan-no (Borrower Loan). The table returned from this will be as follows: Eliminate rows that does not satisfy the selection criteria Borrower.Loan-no = Loan.Loanno from Borrower Loan = Borrower.Cust- Borrower.Loan- Loan.LoanLoan.Amount name no no Ram L-13 L-13 1000 Ram L-13 L-30 20000 Ram L-13 L-42 40000 Shyam L-30 L-13 1000 Shyam L-30 L-30 20000 Shyam L-30 L-42 40000 Suleman L-42 L-13 1000 Suleman L-42 L-30 20000 Suleman L-42 L-42 40000 And will remove one of the column named Loan-no.
Department of Electrical and Electronics By: Sulabh Bansal

Lecture Notes For DBMS and Data Mining and Data Warehousing

i.e.
Loan-no L-13 L-30 L-42

=
Amount 1000 20000 40000

Cust-name Ram Shyam Suleman

Division Operation: denoted by is used for queries that include the phrase for all. For example Find customers who has an account in all branches in branch city Agra. This query can be solved by following statement. Customer-name. branch-name ( ) branch-name (Branch-city=Agra(Branch) The division operations can be specified by using only basic operations as follows: Let r(R) and s(S) be given relations for schema R and S with r s = R-S(r) - R-S ((R-S (r) s) - R-S,S (r))

Department of Electrical and Electronics

By: Sulabh Bansal

You might also like