UNIT 2 - Book Back Exercises ASSIGNMENT
UNIT 2 - Book Back Exercises ASSIGNMENT
UNIT 2 - Book Back Exercises ASSIGNMENT
a. πperson_name(σcity=′Miami′(employee))
b. πperson_name(σsalary>100000(works))
c. πperson_name(σcity=′Miami′∧salary>100000(employee⋈works))
2. Consider the bank database. Give the expression in the relational algebra for each of the following queries.
branch(branch name, branch city, assets)
customer (customer name, customer street, customer city)
loan (loan number, branch name, amount)
borrower (customer name, loan number)
account (account number, branch name, balance)
depositor (customer name, account number)
a. Find the names of all branches located in “Chicago”.
b. Find the names of all borrowers who have a loan in branch “Downtown”.
c. Find the sum of loan amount sanctioned from the branch “Chicago”
a. Find the names of all employees who work for “First Bank Corporation”.
b. Find the names and cities of residence of all employees who work for “First Bank Corporation”.
c. Find the names, street address, and cities of residence of all employees who work for “First Bank
Corporation” and earn more than $10,000.
a. πtitle(σdept_name=′Comp.Sci.′∧credits=3(course))
b. πID(σname=′Einstein′(instructor⋈teaches))
c. gmax (πsalary(instructor))
6. Write the following queries in Relational algebra, using the university schema.
department(dept_name, building, budget)
course(course_id, title, dept_name, credits)
instructor(ID, name, dept_name, salary)
section(course_id, sec_id, semester,year,building,room_number, time_slot_id)
teaches(ID,course_id, sec_id,semester,year)
a. Find all instructors earning the highest salary (there may be more than one with the same salary).
b. Find the enrolment of each section that was offered in Autumn 2009.
c. Find the lowest salary of any instructor.
a. gmax (πenrollment(σsemester=′Autumn′∧year=2009(section)))
b. πcourse_id, sec_id, semester, year, enrollment(σenrollment=max(enrollment)(σsemester=′Autumn
′∧year=2009(section)))
c. gmax(πsalary(instructor))
8. Consider the bank database. Construct the following Relational algebra queries for this relational
database.
branch(branch name, branch city, assets)
customer (customer name, customer street, customer city)
loan (loan number, branch name, amount)
borrower (customer name, loan number)
account (account number, branch name, balance)
depositor (customer name, account number)
a. Find all customers who have an account at all the branches located in “Brooklyn”.
b. Find out the total sum of all loan amounts in the bank.
c. Find the names of all branches that have assets greater than those of at least one branch located in
“Brooklyn”.
10. Consider the employee database. Give the Relational Algebra expression for each of the following queries.
employee (employee name, street, city)
works (employee name, company name, salary)
company (company name, city)
manages (employee name, manager name)
a. Find all employees in the database who earn more than each employee of “Small Bank Corporation”.
b. Assume that the companies may be located in several cities. Find all companies located in every city in
which “Small Bank Corporation” is located.
c. Find the company that has the most employees.
a. πcompany name(gmax(gcount(works)))
b. πcompany name(σavg(salary)>avg(σcompany name=′FirstBankCorporation′(works))(works))
c. πemployee name, city(σcompany name=′FirstBankCorporation′(works⋈employee))
12. Write the following queries in Relational algebra using the university schema.
student (student-id, name, program)
department(dept_name, building, budget)
course(course_id, title, dept_name, credits)
instructor(ID, name, dept_name, salary)
section(course_id, sec_id, semester,year,building,room_number, time_slot_id)
teaches(ID,course_id, sec_id,semester,year)
a. Find the names of all students who have taken at least one Comp. Sci. course; make sure there are no duplicate
names in the result.
b. Find the IDs and names of all students who have not taken any course offering before Spring 2009.
c. For each department, find the maximum salary of instructors in that department. You may assume that every
department has at least one instructor.
a. πname(σdept_name=′Comp.Sci.′(course⋈section⋈teaches⋈student))
b. πstudent-id, name(student−πstudent-id, name(σyear<2009 ∧ semester<′Spring′
(section⋈teaches⋈student)))
c. πdept_name, max_salary( gmax(salary)(instructor))
13. Write the following queries in Relational algebra, using the university schema.
student (student-id, name, program)
department(dept_name, building, budget)
course(course_id, title, dept_name, credits)
instructor(ID, name, dept_name, salary)
section(course_id, sec_id, semester,year,building,room_number, time_slot_id)
teaches(ID,course_id, sec_id,semester,year)
a. For each department, find the maximum salary of instructors in that department. You may assume that
every department has at least one instructor.
b. Find the lowest, across all departments, of the per-department maximum salary computed by the preceding
query.
a. Find the number of accidents in which the cars belonging to “John Smith” were involved.
b. Find the car with the license number “AABB2000” in the accident with report number “AR2197” to
$3000.
a. gcount(πreport number(σname=′JohnSmith′(person⋈owns⋈participated⋈accident)))
b. πlicense(σreport number=′AR2197′ ∧ damage amount≤3000(accident⋈participated))
15. Consider the bank database. Construct the following Relational algebra queries for this relational
database.
branch(branch name, branch city, assets)
customer (customer name, customer street, customer city)
loan (loan number, branch name, amount)
borrower (customer name, loan number)
account (account number, branch name, balance)
depositor (customer name, account number)
a. Find all customers of the bank who have an account but not a loan.
b. Find the names of all customers who live on the same street and in the same city as “Smith”.
c. Find the names of all branches with customers who have an account in the bank and who live in “Harrison”.
=employee2.city)(ρemployee2 (employee)))
b. πemployee name(σsalary>avg_salary(employee⋈works))
c. πcompany name( gmin (payroll)(company⋈works))
17. Consider the bank database. Construct the following Relational algebra queries for this relational
database.
a. Find the names of all customers who have a loan, an account, or both, from the bank
b. Find the names of all customers who have a loan at the Perryridge branch.
c. 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.
a. πcustomer_name(depositor∪borrower)
b. πcustomer_name(σbranch_name=′Perryridge′(borrower))
c. πcustomer_name(σbranch_name=′Perryridge′(borrower)−depositor)
18. Consider the bank database. Construct the following Relational algebra queries for this relational
database.
a. gmax(πbalance(account))
b. πcustomer_name, amount(loan⋈borrower)
c. πcustomer_name(σcustomer_name∈(depositor∩borrower)(customer))
19. Consider the bank database. Construct the following Relational algebra queries for this relational
database.
20. Consider the bank database. Construct the following Relational algebra queries for this relational
database.
member(memb no, name, age)
book(isbn, title, authors, publisher)
borrowed(memb no, isbn, date)
a. Find the names of members who have borrowed any book published by “McGraw-Hill”.
b. Find the names of members who have borrowed all books published by “McGraw-Hill”.
c. For each publisher, find the names of members who have borrowed more than five books of that publisher.
a. πname(σpublisher=′McGraw−Hill′(book⋈borrowed⋈member))
b. πname(member−πname(σpublisher=′McGraw−Hill′(book⋈borrowed⋈member)))
c. πpublisher, name(σcount>5(group by publisher, name(book⋈borrowed⋈
member)))
21. Consider the Library database. Construct the following Relational algebra queries for this relational
database.
member(memb no, name, age)
book(isbn, title, authors, publisher)
borrowed(memb no, isbn, date)
a. For each publisher, find the name and membership number of members who have borrowed more
than five books of that publisher.
b. Find the average number of books borrowed per member. Take into account that if an member does
not borrow any books, then that member does not appear in the borrowed relation at all.
22. Consider the bank database. Construct the following Relational calculus for this relational database.
a. Find the loan number for each loan of an amount greater than 6000
b. Find the names of all customers who have a loan and an account at the bank
c. Find the names of all customers who have a loan at the Mexico branch, but no account at any branch
of the bank
a. {loan_number∣∃loan(loan_amount(loan)>6000∧loan_number=
loan_number(loan))}
b. {customer_name∣∃loan(borrower(customer_name,loan_number)∧
∃account(depositor(customer_name,account_number)))}
c. {customer_name∣∃loan(borrower(customer_name,loan_number)∧
branch_city(Mexico,branch)∧¬∃account(depositor(customer_name,
account_number)))}
23. Consider the employee database. Give Relational Algebra expression for each of the following queries.
employee (employee name, street, city)
works (employee name, company name, salary)
company (company name, city)
manages (employee name, manager name)
a. πemployee name(manages)
b. πemployee name(employee−manages)
c. πemployee name(σcity=′NewYork′(works⋈company))
24. Consider the bank database. Construct the following Tuple Relational calculus for this relational
database.
branch (branch_name, branch_city, assets)
customer (customer_name, customer_street, customer_city)
account (account_number, branch_name, balance)
loan (loan_number, branch_name, amount)
depositor (customer_name, account_number)
borrower (customer_name, loan_number)
a. Find the names of all customers having a loan from the New York branch, and the cities in which they
live.
b. Find the names of all customers who have an account at all branches located in Brooklyn
c. Find the names of all customers who have a loan and an account at the bank
a. {c.customer_name,c.customer_city∣borrower(c.customer_name,
l.loan_number)∧loan(l.loan_number,b.branch_name,_)∧
branch(b.branch_name,′NewYork
′,_)∧customer(c.customer_name,_,c.customer_city)}
b. {c.customer_name∣∀b(branch(b.branch_name,′Brooklyn′,_)→
∃a(account(c.customer_name,a.account_number,_)))}
c. {c.customer_name∣∃d(depositor(c.customer_name,d.account_number)∧∃b(b
orrower(c.customer_name,b.loan_number)))}
25. Consider the insurance database. Construct the following Relational Algebra queries for this relational
database.
person (driver id, name, address)
car (license, model, year)
accident (report number, date, location)
owns (driver id, license)
participated (report number, license, driver id, damage amount)
a. Find the model of the car met with accidents in which the cars belonging to “Alex”.
b. Find the driver id with the license number and date who makes damage amount greater than $3000.
a. πmodel(σdriver_id="Alex"(owns⋈participated⋈car))
b. πdriver_id, license, date(σdamage_amount>3000(participated))
26. Consider the bank database. Construct the following Domain Relational calculus for this relational
database.
a. Find the loan_number, branch_name, and amount for loans of over $1200
b. Find the names of all customers who have a loan of over $1200
c. Find the names of all customers who have a loan from the Perryridge branch and the loan amount.
a. {⟨loan_number,branch_name,amount⟩∣loan(loan_number,branch_name,
amount)∧amount>1200}
b. {customer_name∣∃loan_number,branch_name,amount(borrower
(customer_name,loan_number)∧loan(loan_number,branch_name,
amount)∧amount>1200)}
c. {customer_name∣∃loan_number,amount(borrower(customer_name,
loan_number)∧loan(loan_number,"Perryridge",amount))}
27. Consider the Library database. Construct the following Relational algebra queries for this relational
database.
member(memb no, name, age)
book(isbn, title, authors, publisher)
borrowed(memb no, isbn, date)
a. Find the names of members who borrowed a book with 'Database' in its title
b. Find the titles of books borrowed by members under the age of 18.
c. Find the names of members who borrowed a book published by 'Pearson’.
a. Find the names of all customers having a loan, an account, or both at the Perryridge branch
b. Find the names of all customers who have an account at all branches located in Brookly
a. {x.customer_name∣∃y,z(depositor(x.customer_name,y.account_number)∨b
orrower(x.customer_name,z.loan_number))∧(y.branch_name="Perryridge
"∨z.branch_name="Perryridge")}
b. {x.customer_name∣∀y(branch(y.branch_name,"Brooklyn",_)→
∃z(depositor(x.customer_name,z.account_number)∧z.branch_name=
y.branch_name))}
29.
Ans: JFTT
30.
Ans: 1