Download presentation
Presentation is loading. Please wait.
Published byMarcus Long Modified over 8 years ago
1
1 Session 3 Welcome: To session 3-the fourth learning sequence “Relational algebra “ Recap : In the previous learning sequences, we discussed the four operators of relational algebra. Present learning: We shall explore the following topic: Example Queries - Example Queries
2
2 Relational Algebra
3
uA basic expression in the relational algebra consists of either one of the following: wA relation in the database wA constant relation
4
Relational Algebra uLet E 1 and E 2 be relational-algebra expressions; the following are relational-algebra expressions: wE 1 E 2 wE1 E2 wE 1 - E 2 wE 1 x E 2 w p (E 1 ), P is a predicate on attributes in E 1 w s (E 1 ), S is a list consisting of some of the attributes in E 1 w x (E 1 ), x is the new name for the result of E 1 wThe assignment operation ( )
5
Relational Schema for the Banking Enterprise ubranch (branch-name, branch-city, assets) ucustomer (customer-name, customer-street, customer-only) uaccount (account-number, branch-name, balance) uloan (loan-number, branch-name, amount) udepositor (customer-name, account-number) uborrower (customer-name, loan-number)
6
Example Queries uFind all loans of over $1200. n Find the loan number for each loan of an amount greater than $1200. amount > 1200 (loan) loan-number ( amount > 1200 (loan))
7
Example Queries uFind the names of all customers who have a loan, an account, or both, from the bank. n Find the names of all customers who have a loan and an account at bank. customer-name (borrower) customer-name (depositor) customer-name (borrower) customer-name (depositor)
8
Example Queries uFind the names of all customers who have a loan at the Perryridge branch. n Find the names of all customers who have a loan at the Perryridge branch but do not have an account at any branch of the bank. customer-name ( branch-name = “Perryridge” ( borrower.loan-number = loan.loan-number ( borrower x loan ))) – customer-name ( depositor ) customer-name ( branch-name=“Perryridge ” ( borrower.loan-number = loan.loan-number (borrower x loan)))
9
Example Queries uFind the names of all customers who have a loan at the Perryridge branch. Query 2 customer-name ( loan.loan-number = borrower.loan-number ( ( branch-name = “Perryridge” (loan)) x borrower)) Query 1 customer-name ( branch-name = “Perryridge” ( borrower.loan-number = loan.loan-number (borrower x loan)))
10
Example Queries Find the largest account balance uRename account relation as d uThe query is: balance (account) - account.balance ( account.balance < d.balance (account x d (account)))
11
11 Relational Algebra Summary: In this learning sequence, we discussed some example queries.
12
12 END
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.