You are on page 1of 14

Relational Model (Part-2 of 2)

Example of Relations
Banking Example
1. branch (branch_name, branch_city, assets)

2. customer (customer_name, customer_street,


customer_city)

3. account (account_number, branch_name, balance)

4. loan (loan_number, branch_name, amount)

5. depositor (customer_name, account_number)

6. borrower (customer_name, loan_number)


1. The branch relation
2. customer Relation
3. Account Relation
4. The loan relation
5. The depositor Relation
6. The borrower relation
Example Queries
1. branch (branch_name, branch_city, assets)
2. customer (customer_name, customer_street, customer_city)
3. account (account_number, branch_name, balance)
4. loan (loan_number, branch_name, amount)
5. depositor (customer_name, account_number)
6. borrower (customer_name, loan_number)

 Find all loans of over $1200

 Find the loan number for each loan of an amount


greater than $1200
 Find the names of all customers who have a loan,
an account, or both, from the bank
Answers: Example Queries
 Find all loans of over $1200

amount > 1200 (loan)

 Find the loan number for each loan of an amount greater


than $1200

loan_number (amount > 1200 (loan))

 Find the names of all customers who have a loan, an


account, or both, from the bank

customer_name (borrower)  customer_name (depositor)


Example Queries
1. branch (branch_name, branch_city, assets)
2. customer (customer_name,
customer_street, customer_city)
3. account (account_number, branch_name,
balance)
4. loan (loan_number, branch_name, amount)
5. depositor (customer_name,
account_number)
 Find the names of all customers who have a loan at the
6. borrower (customer_name, loan_number)
Perryridge branch.
 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.
Answers: Example Queries
 Find the names of all customers who have a loan at the
Perryridge branch.

customer_name (branch_name=“Perryridge”
(borrower.loan_number = loan.loan_number(borrower x
loan)))
 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)
Alternate Method
 Find the names of all customers who have a loan at
the Perryridge branch.

Query 1

customer_name (branch_name = “Perryridge” (


borrower.loan_number = loan.loan_number (borrower x
loan)))
Query 2

customer_name(loan.loan_number = borrower.loan_number (

(branch_name = “Perryridge” (loan)) x


borrower))
Reference

System Concepts
Abraham Silberschatz, Henry F. Korth, S. Sudarshan
Tata McGraw-Hill

You might also like