Quiz 3 DBMS - Solution
Quiz 3 DBMS - Solution
Technology
Faculty of Computer Science and Engineering
CS-232 Introduction to Databases
QUIZ # 3
25 Marks
*All questions in this quiz are mapped onto CLO-3
Name Dated: 16th Dec 2022
Registration # Time: 40 minutes
Question 1. Given that you have a relation called “instructor”, consider the query
as given below and write output. In case you think there is an issue with the query,
you need to identify the problem.
(2 Marks)
Page 1 of 6
Name Dated: 19th May 2022
Registration #
A. Find the ID of each customer of the bank who has an account but not a loan.
Explanation:
We can see that account number is a foreign key in the depositor relation, and by domain
knowledge we know that if a person opens an account, he/she must deposit an initial amount.
Clearly, we can find IDs of all those who have account using the depositor relation. Similarly, a
customer’s id will only exist in borrower relation if and only if there is some loan against him
B. Find the ID of each customer who lives on the same street and in the same city as customer '12345' .
Select F.ID
From customer as F, customer as S
Where F.customer_street = S.customer_street
AND F.customer_city = S.customer_city
AND S.customer_id = ‘12345’
C. Find the name of each branch that has at least one customer who has an account in the bank and who lives
in “Harrison”.
Select DISTINCT branch_name
From account, depositor, customer
Where customer.id = depositor.id
AND depositor.account_number = account.account_number
AND customer_city = ‘Harrison’
Page 2 of 6
Name Dated: 19th May 2022
Registration #
D. Find the names of all branches that have assets greater than those of at least one branch located in
“Brooklyn”.
Select branch_name
From branch
Where assets > some
(
Select assets
From branch
Where branch.city = ‘Brooklyn’
)
Question 3. Consider the employee database as shown in the figure below, where
the primary keys are underlined. Construct the following SQL queries for this
relational database
(2 x 3 = 6 Marks)
Page 3 of 6
Name Dated: 19th May 2022
Registration #
C. Delete all tuples in the works relation for employees of “Small Bank Corporation”.
(3 Marks)
Question 5. Considering the following data (tables and schema), answer the
questions by writing queries using JOINS.
(3 x 2 = 6 Marks)
Page 4 of 6
Name Dated: 19th May 2022
Registration #
A. Write query to obtain date, item_name, is_veg, price, and units_sold using both tables, however, it is not
necessary that data between both tables must match i.e. there is a possibility that some information is missing
from either of the two tables
SELECT
d.date,
i.name,
i.is_veg,
d.price,
d.units_sold
FROM daily_menu d
FULL OUTER JOIN menu_items i
ON d.item_id = i.item_id
Page 5 of 6
Name Dated: 19th May 2022
Registration #
B. Write query to obtain date, item_name, is_veg, price, and units_sold using both tables, it is essential that all
information from daily_menu table must be present however, there maybe cases that some information is
missing from menu_items table
SELECT
d.date,
i.name,
i.is_veg,
d.price,
d.units_sold
FROM daily_menu d
LEFT JOIN menu_items i
ON d.item_id = i.item_id
Page 6 of 6