Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Course Title: Introduction to Database Systems

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)

Follow the instructions given above.


Business Case: Vaccination Center
Draw ERD to show entity, attributes, and relations between these entities.
Expo center Lahore is providing facilities of Vaccination in which they have vaccination staff,
Citizen, Vaccination record and Halls. Vaccination staff has its own identity from ID, Name,
qualification, Designation, Age and Salary. They also have Vaccination record in which they will
maintain Vaccination number, Company name, Age group and quantity. Citizen who has CNIC,
name, age, blood group, blood pressure, date of vaccination and vaccination number will be
maintain in Citizen record. They are also maintaining record of each citizen in Citizen details in
which they are maintaining CID, Citizen type (Doctor, Teacher, Disable or others), No of doses,
Side effect (if any). There are 4 halls one for doctors one for teachers one for disable and one
for others. On entry you will go to specific hall in which they will give you slip that may contain
hall No, Citizen CNIC, Designation, Citizen type. Vaccination staff has many vaccinations, and
they are maintaining record of each vaccination. Each citizen is allowed only one vaccine at a
time. Each hall has many citizens in which they are entry record of each citizen and give you
slip in which your record is mentioned.

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

Integer String String Fixed String String (10)


PK Not String FK on Employee
Null (4 Digits)

CREATE TABLE Vehicles (


RegNo int NOT NULL PRIMARY KEY,
Make varchar(255) NOT NULL,
Model varchar(255),
Year char(4),
Color varchar(20),
Eid varchar(10),
FOREIGN KEY(Eid) REFERENCES Employee(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.

Select employee.name, transaction.transaction.id from employee Join transaction ON


employee.eid= transaction.eid and DATE (traction. transaction_date) = “2021-22-12”

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)

You might also like