Dbms Model Lab
Dbms Model Lab
d. Display the passengers who had booked the journey from Bangalore to Chennai on 03-NOV-
2014.
e. List the details of passengers who have traveled more than three times on the same route.
f. Create a view that displays the RouteNo, source, destination and journey_date which moves
from Chennai to Pune.
2. Consider the following relations for a boat management application for a beach resort:
SAILOR (SID, NAME, DOB, GENDER)
BOAT (BID, BTYPE, BNAME, COLOR)
BTYPE can take two values (D, S)
D – Deluxe
S –Super Deluxe
SAILS (SID, BID, DOT, SHIFT)
DOT – Date of Trip
SHIFT can take two values – FN or AN
A sailor is assigned a boat on a day. A sailor is permitted to sail the boat for only one shift on a
day.
a. The primary keys are underlined. Identify the foreign keys .Draw the ER diagram
b. Create the above mentioned tables and populate the tables
c. Include constraints for BTYPE and SHIFT as mentioned above
d. Develop a SQL query to list the details of boats whose type is Super Deluxe and Color is
Red.
e. Develop a view that will keep track of sailor id, sailor name, date of trip, boat id, boat type,
boat name and shift.
e. Create a view that will keep track of the details of each customer and the number of orders
placed by each customer
11. Consider the following relational schema for a company database application:
EMPLOYEE (ENO, NAME, GENDER, DOB, DOJ, DESIGNATION, BASIC,
DEPT_NO, PAN, SENO)
Implement a Check Constraint for GENDER
PAN – Permanent account Number ,SENO – Supervisor Employee Number
DEPARTMENT (DEPT_NO, NAME, MENO)
MENO - Manager Employee Number
PROJECT (PROJ_NO, NAME, DEPT_NO)
WORKSFOR (ENO, PROJ_NO, DATE_WORKED, HOURS)
a. The primary keys are underlined. Identify the foreign keys . Draw the ER diagram
b. Create the above mentioned tables and populate the tables
c. Include the constraints as mentioned above.
d. Develop a SQL query to list the details of department which has more than 3 employees
working for it.
e. Create a view that keeps track of DeptNo, DeptName and number of employees in each
department.
f. Develop an SQL query to list the departments and the details of manager in each
department.
12. Consider the following relational schema for a Product Sales database application:
Product (Prodid, Prodesc, Price, Stock)
Purchase (Purid, Proid, qty, supplierName)
Sales (Saleid, Proid, qty, custname)
a. The primary keys are underlined. Identify the foreign keys. Draw the ER diagram
b. Create the above mentioned tables and populate the tables
c. Include the constraint on Saleid that it starts with letter ‘S’.
d. Display the ProdID and the sum of quantity purchased for each product.
e. Create a view that keeps track of Prodid, price, Purid, qty and customerName who made
the purchase.
13. Consider the following relational schema for a Sales database application:
Product (Prodid, Prodesc, Price, Stock)
Purchase (Purid, Proid, qty, supplierName)
Sales (Saleid, Proid, qty, custname)
a. The primary keys are underlined. Identify the foreign keys. Draw the ER diagram
b. Create the above mentioned tables and populate the tables
c. Include the constraint on Saleid that it starts with letter ‘S’.
d. Display the ProdIDs of the product which are purchased more than 5 times
e. Create a view that keeps track of Prodid, price, Purid, qty and customerName who made
the purchase.
14. Consider the following relational schema for a Loan database application:
Customer (Custid, Custname, Age, phno)
HLoan (HLoanid, Amount, Custid)
VLoan (VLoanid, Amount, Custid)
Where HLoan is Housing loan and VLoan is a Vechile loan.
a. The primary keys are underlined. Identify the foreign keys and draw schema diagram
b. Create the above mentioned tables and populate the tables
c. Include the constraint on HLoanid that it starts with letter ‘H’ and VLoanid starts with
letter ‘V’.
d. Display the number of VLoan taken by a particular customer id
e. Display the list of the customerids and total HLoan amount taken.
f. Create a view that keeps track of customer details who have taken both HLoan and VLoan.
15. Consider the following relational schema for a Loan database application:
Customer (Custid, Custname, Addr, phno,pan_no)
Loan (Loanid, Amount, Interest,Custid)
Account (Accid, Accbal, Custid)
a. The primary keys are underlined. Identify the foreign keys and draw schema diagram [5]
b. Create the above mentioned tables and populate the tables [10]
c. Include the constraint on Custid that it starts with letter ‘C’
d. Display the customer id, name and account balance. Sort the output using custid
e. Display the accounts of custids ‘C01’,’C02’,’C03’
f. Display the custid who has account balance larger than other customers
h. Create a view that keeps track of customer id, loan amount and account balance.
16. Consider the following relational schema for a Loan database application:
Customer (Custid, Custname, Age, phno)
Loan (Loanid, Amount, Custid)
a. The primary keys are underlined. Identify the foreign keys . Draw the ER diagram
b. Create the above mentioned tables and populate the tables
c. Include the constraint on Loanid that it starts with letter ‘L’.
d. Display the list of the customerids and total Loan amount taken
e. Display the CustId and CustName who have taken less than 2 loans
f. Create a view that keeps track of Custid, Custname, loanid and loan amount.
17. Consider the following relational schema for a Sales database application:
Product (Prodid, Prodesc, Price, Stock)
Purchase (Purid, Proid, qty, supplierName)
Sales (Saleid, Proid, qty, custname)
a. The primary keys are underlined. Identify the foreign keys
b. Create the above mentioned tables and populate the tables
c. Include the constraint on Saleid that it starts with letter ‘S’
d. Display the names who are both supplier as well as customer
e. Display the amount (price * qty) of Products in each Sales.
f. Create a view which displays Product ids and sum of quantity in sales
18. Consider the following relational schema for a Loan database application:
Customer (Custid, Custname, Age, phno)
Loan (Loanid, Amount, Custid, Emi)
a. The primary keys are underlined. Identify the foreign keys and draw schema diagram
b. Create the above mentioned tables and populate the tables
Note: Read all questions and populate values accordingly.
c. Include the constraint on Custid that it starts with letter ‘C’.
d. Update the loan amount by increase in 2 % for all customers
e. Display the custid and Custname whose loan amount lies in the range of 30,000 to 50,000
f. Display the CustId and CustName who have taken less than 2 loans
g. Create a view that keeps track of Custid, Custname, loanid and loan amount.
19. Consider the following relational schema for a Books Ordering database application:
Books (isbn, title, author, stock_qty, price, pub_year)
Customers (cust_id, cust_name, address)
Orders (order_no, cust_id, order_date) where cust_id refs
Customers(cust_id)
Order_list (order_no, isbn, qty, ship_date) where order_no refs
Orders(order_no), isbn refs Books (isbn)
a. The primary keys are underlined. Identify the foreign keys
b. Create the above mentioned tables and populate the tables
c. Include the constraint on Cust_id that it starts with letter ‘C’.
d. Display the custid and Custname who have ordered more than 3 books on the same date
e. Display the CustId and CustName who have ordered very few number of books.
f. Create a view that keeps track of books that are ordered on 05-NOV-2014. Display isbn,
title, author, order_no, quantity and order_date.
20. Consider the following relational schema for Products Order database application:
Products (p_id, p_name, retail_price, qty_on_hand)
Orders (order_id, order_date)
Order_details (order_number, product_number, qty_ordered)
Where: order_number references order_id
product_number references p_id
a. The primary keys are underlined. Identify the foreign keys
b. Create the above mentioned tables and populate the tables .
c. Include the constraint on orderid that it starts with letter ‘O’.
d. Display the ProdID and the sum of quantity ordered for each product.
e. Create a view that keeps track of P_id, price, order_id, qty_ordered and ordered_date.