Professional Documents
Culture Documents
Intro To DB Mid Summer 2022 Theory Solution
Intro To DB Mid Summer 2022 Theory Solution
Mid Term
Sections:
D1 Semester: Summer 2022
Course Code: CSDB2313 Marks: 75
Duration: 1.5 Hours Time:
Date: Program: BSCS
Instructions
Attempt all questions and their parts in sequence.
Start each question on a new page.
Avoid using extra sheet.
Attach question paper with the answer book.
Only use Black/Blue ink to attempt the paper. Pencil is allowed for figures only.
Using any other color (Red, Orange, Purple, Green etc) will result in 0 marks in
the paper.
Answer all questions in context of class discussions.
State all your assumptions clearly.
Use of Electronic Gadgets (Laptops, Mobiles, Calculators, and Smart Watches
etc.) is not allowed.
No Bathroom or Water Breaks allowed during this exam.
Introduction to Database Systems (Mid Term 1 Introduction to Database Systems (Mid Term)
Exam) Exam)
Name: Roll Number:
SECTION 1 MARKS: 20
========================================================================
Question 1 (10 Marks)
Solution:
Introduction to Database Systems (Mid Term 2 Introduction to Database Systems (Mid Term)
Exam) Exam)
QUESTION 2 (10 Marks)
====================================================================
Apply Mapping rules to the given ER Diagram and convert it into relational schema.
Introduction to Database Systems (Mid Term 3 Introduction to Database Systems (Mid Term)
Exam) Exam)
Solution:
Introduction to Database Systems (Mid Term 4 Introduction to Database Systems (Mid Term)
Exam) Exam)
SECTION 2 (DDL Part) MARKS: 15
=======================================================================
For each of the following, provide SQL statement that fulfill the given requirements
Introduction to Database Systems (Mid Term 5 Introduction to Database Systems (Mid Term)
Exam) Exam)
Q1. Add a table for vehicles with the following attributes [10 Marks]
RegNo Make Model Year Color Eid
Q2. Add the column for Employee Supervisor varchar (15) in the Employee table. [5 Marks]
ALTER TABLE Employee
ADD Supervisor varchar(15);
Introduction to Database Systems (Mid Term 6 Introduction to Database Systems (Mid Term)
Exam) Exam)
SECTION 3 MARKS 40
========================================================================
Using the given database write the SQL and Relational Algebra statements to fulfill the
following requirements. Note: Use database which is given in Section 2.
Q1. Show the details of the transactions as well as the associated employee name for the
transactions from yesterday having amount greater than 100,000.
Q2. Show the names of the customers who have a loan account with credit less than 50,000 or
saving account with balance more than 100,000. Also display the relevant account numbers.
Select customer.name, loanaccounts. Account_number, saving accounts. Account_number
FROM loanaccount INNER JOIN customer INNER JOIN saving accounts ON customer.
customer_id = saving accounts. customer_id and customer. customer_id =loanaccounts.
customer_id and saving accounts. current balance >100000 and loanaccounts. current
credit > 50000.
Q3. Write a query to display all the saving account number with their owner’s name.
Select customer.name, saving accounts. Account_number FROM saving account LEFT
JOIN customer ON customer. customer_id = saving accounts. customer_id.
Q4. Show complete transaction details along with customer name for the saving accounts where
the total transacted amount for the account is more than 1,500,000.
Select employee.name, transaction. transaction_details from employee Join transaction
ON employee.eid= transaction.eid where transaction_amount > 1500000.
Q5. Display the name of the employees who have a loan account in any bank with the bank
name starting with ‘M’.
Select employees.eid , employees.name From employees INNER JOIN branch ON
emplyees.brach_id = branch.branch.id INNER JOIN bank ON bank.bank_id =
branch.bank_id and bank.bank_name LIKE ‘M%’.
Q6. Display the name of the customers who do not have a loan account.
Introduction to Database Systems (Mid Term 7 Introduction to Database Systems (Mid Term)
Exam) Exam)
Select Customer_Name from Customers where loan_account is not null;
Q7. Write a query to display employee name along with the total amount of transactions
conducted by the employee. Note: If an employee has not done any transaction, then his
transaction amount should be NULL or 0.
Select employee.name, transaction.transaction_amount FROM employees RIGHT JOIN
transactions ON employee.eid = transaction.eid.
Q8. Write a query to display customer name with branch address who have same amount in
their saving and loan accounts.
Select customer.name , branch.branch_address FROM customer JOIN loanaccounts ON
customer.customer_id =loanaccounts.customer_Id JOIN branch ON
loanaccounts.branch_id = branch.branch_id.
Q9. Write a query to display number of employees in each branch of each bank.
Select Count(employee.id) FROM employee JOIN Branch ON branch.branch_id
=employee.branch_id GROUP BY branch_id.
Q10. Write a query to display all the names of employees with total amount of transaction till
now.
Select customer.name, loanaccounts.Account_number , savingaccounts.Account_number
FROM loanaccount OUTER JOIN customer OUTER JOIN savingaccounts ON
customer.customer_id = saving accounts.customer_id and customer.customer_id
=loanaccounts.customer_id.
Introduction to Database Systems (Mid Term 8 Introduction to Database Systems (Mid Term)
Exam) Exam)