Anna University: Chennai 600 025 B.E / B.Tech Degree Examinations, October / Novemebr 2014 R-2013 Third Semester Cs6312: Database Management Systems Laboratory Time: 3 Hours MARKS: 100
Anna University: Chennai 600 025 B.E / B.Tech Degree Examinations, October / Novemebr 2014 R-2013 Third Semester Cs6312: Database Management Systems Laboratory Time: 3 Hours MARKS: 100
com
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 [15]
d. Display the passengers who had booked the journey from Bangalore to Chennai on 03-
NOV-2014. [10]
e. List the details of passengers who have traveled more than three times on the same route.
[10]
f. Create a view that displays the RouteNo, source, destination and journey_date which
moves from Chennai to Pune. [10]
h. Create a PL / SQL stored procedure that accepts journey_date and displays list of
passengers booked ticket on that date. [20]
i. In the above created procedure, include exceptions to display "No ticket booked on
specified date" for a given journey_date [20]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
2. Consider the following relations for a boat management application for a beach resort:
D – Deluxe
S –Super Deluxe
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 and draw schema
diagram [5]
b. Create the above mentioned tables and populate the tables [15]
d. Develop a SQL query to list the details of boats whose type is Super Deluxe and Color is
Red. [10]
e. Develop a view that will keep track of sailor id, sailor name, date of trip, boat id, boat type,
boat name and shift. [20]
g. Create a PL / SQL stored function that accepts SID and returns the name of sailor [20]
h. In the above created function, include exceptions to display "No such Sailor exist"
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [20]
c. Ensure that product names should be within Laptop, Mouse, Server, Air conditioner
[5]
d. Develop a SQL query to list the details of products whose unit price is greater than the
e. List the customer names who have orders more number of products [10]
f. Create a view that displays the PCODE, PNAME and NOU of the product ordered [10]
g. Create a function that accepts PCODE, Unit_Price and NOU. Calculate the total_cost
of the ordered product. Return the total_cost. [20]
h. Create a sequence named Product_Sequence that will get incremented by 1. Use the
created sequence while inserting PCODE into Product table. [20]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [15]
c. Include constraints that the routeNo starts with letter 'R' and gender of driver is always
'Male' [10]
d. Develop a SQL query to list the details of drivers who have traveled more than three
e. Create a sequence named Driver_Sequence that will get incremented by 1. Use the created
f. Create a view that displays the DID, DNAME assigned for RouteNo 'R5' on 02-NOV-2014
[20]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [20]
c. Include the constraint as mentioned above and the gender of driver is always 'male'. [10]
d. Develop a SQL query to list the details of each driver and the number of trips traveled.
[10]
f. Create a view that displays the Driver details and also the city in which he drives a truck
[20]
g. Create a procedure that displays the details of all drivers, the truck_code and DOT. Use
cursors appropriately. [30]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [30]
d. Develop a SQL query to list the order number and number of items in each order [10]
f. Create a view that will keep track of the details of each customer and the number of orders
placed by each customer [20]
g. Develop a database trigger that will not permit to insert more than six records in the
CUST_ORDER relation for a particular order. (An order can contain a maximum of six
items). [20]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [15]
d. Write a query that lists the customer details and the number of accounts each customer
has. [10]
e. Create a sequence named Customer_Sequence which gets incremented by 10 and use this
f. Create a view that will keep track of the details of each customer and account details who
have both savings and current account. [10]
g. Develop a database procedure that will accept transaction id, account number, transaction
type, transaction date and transaction amount as input and insert a record into
TRANSACTION table subject to the following conditions:
i. If TTYPE =’D’ the value of BALANCE in the ACCOUNT table must be
incremented by the value of TAMOUNT
ii. If TTYPE =’W’ the value of BALANCE in the ACCOUNT table must be
decremented by the value of TAMOUNT.
If a minimum balance of Rs. 2000/- will be maintained for a savings account and
a minimum balance of Rs. 5000/- will be maintained for a current account else
appropriate messages must be displayed [30]
h. In the above created procedure, if TTYPE = ‘W’, and transaction amount is > available
balance, raise exceptions to display “Amount > available Balance” [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [20]
d. Develop a SQL query to list the details of branches and the number of accounts in each
branch. [10]
e. Develop a SQL query to list the details of customers who have performed three
transactions on a day [15]
f. Create a view that will keep track of the details of each customer and account details who
have both savings and current account. [10]
g. Develop a database trigger that will update the value of BALANCE in ACCOUNT table
when a record is inserted in the transaction table. Consider the following cases:
i. If TTYPE =’D’ the value of BALANCE in the ACCOUNT table must be
incremented by the value of TAMOUNT
ii. If TTYPE =’W’ the value of BALANCE in the ACCOUNT table must be
decremented by the value of TAMOUNT.
If a minimum balance of Rs. 2000/- will be maintained for a savings account and
a minimum balance of Rs. 5000/- will be maintained for a current account else
appropriate messages must be displayed [30]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [25]
d. Develop a SQL query to list the details of borrowers who do not have any books checked
out. [5]
e. Develop a SQL query to list the details of borrowers who have more than five books
checked out. [10]
g. Create a view that will keep track of the card number, card holders name and number of
books borrowed (Number of books with status ‘T’) [10]
h. Create a procedure named Author_Details that accepts the BookID and displays the author
ID, author name and also the status of the book. [30]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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 [30]
d. Develop a SQL query to list the details of staff who earn less than the basic pay of all
staff. [10]
e. Create a view that keeps track of DeptNo, DeptName and number of staff in each
department. [10]
f. Develop a SQL query to list the details of staff who have more than three skills. [5]
h. Develop a procedure Staff_Increment that will accept staff number and increment amount
as input and update the basic pay of the staff in the staff table. [20]
i. In the above procedure include exception in the procedure that will display a message
“Staff has basic pay null” if the basic pay of the staff is null and display a message “No
such staff number” if the staff number does not exist in the staff table. [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
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
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 [20]
d. Develop a SQL query to list the details of department which has more than 3 employees
working for it. [10]
e. Create a view that keeps track of DeptNo, DeptName and number of employees in each
department. [10]
f. Develop an SQL query to list the departments and the details of manager in each
department. [5]
i. In the above procedure include exception in the procedure that will display a message
“Employee has basic pay null” if the basic pay of the employee is null and display a
message “No such Employee number” if the employee number does not exist in the
employee table. [10]
j. Create a database trigger that will not permit to insert values into Employee table if DOJ
is less than DOB. [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
12. Consider the following relational schema for a Product Sales database application:
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 [20]
c. Include the constraint on Saleid that it starts with letter ‘S’. [5]
d. Display the ProdID and the sum of quantity purchased for each product. [10]
e. Create a view that keeps track of Prodid, price, Purid, qty and customerName who made
the purchase. [20]
f. Create a sequence named Product_Sequence that gets incremented by 10 and use it for
inserting Prodid values in Product table. [10]
g. Develop a procedure named Product_Sales that accepts a prodid and displays all the sales
and purchase records of it. [20]
h. In the above procedure include exception in the procedure that will display a message
“No such Product ID” if the given product id does not exist in the product table. [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
13. Consider the following relational schema for a Sales database application:
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 [20]
c. Include the constraint on Saleid that it starts with letter ‘S’. [5]
d. Display the ProdIDs of the product which are purchased more than 5 times [10]
e. Create a view that keeps track of Prodid, price, Purid, qty and customerName who made
the purchase. [20]
f. Create a sequence named Product_Sequence that gets incremented by 10 and use it for
inserting Prodid values in Product table. [10]
h. Create a database trigger that will not permit a customer to purchase more than 5 products.
[10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
14. Consider the following relational schema for a Loan database application:
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 Loanid that it starts with letter ‘L’. [5]
d. Display the list of the customerids and total Loan amount taken [10]
e. Display the CustId and CustName who have taken less than 2 loans [10]
f. Create a view that keeps track of Custid, Custname, loanid and loan amount. [20]
g. Create a sequence named Customer_Sequence that gets incremented by 3 and use it for
inserting Custid values in Customer table. [10]
h. Develop a function named Customer_Loan which accepts Loanid as input and displays
Custid, CustName and loan_amount. [20]
i. Create a database trigger that will not permit a customer to get more than 3 loans. [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
15. Consider the following relational schema for a Loan database application:
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 HLoanid that it starts with letter ‘H’ and VLoanid starts with
e. Display the list of the customerids and total HLoan amount taken. [10]
f. Create a view that keeps track of customer details who have taken both HLoan and VLoan.
[20]
g. Create a sequence named Customer_Sequence that gets incremented by 3 and use it for
inserting Custid values in Customer table. [10]
h. Develop a procedure named Customer_Loan which accepts HLoanid as input and displays
Custid, CustName and loan_amount of HLoan. [20]
i. In the above procedure include exceptions to display “No such HLoanid” when incorrect
Hloanid is given. [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
16. Consider the following relational schema for a Loan database application:
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’ [5]
d. Display the customer id, name and account balance. Sort the output using custid [10]
f. Display the custid who has account balance larger than other customers [5]
h. Create a view that keeps track of customer id, loan amount and account balance. [20]
i. Develop a procedure named Customer_Loan that displays all the loan details [20]
j. In the above procedure include exceptions to display “No such Loanid” when incorrect
loanid is given. [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
17. Consider the following relational schema for a Sales database application:
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 [20]
c. Include the constraint on Saleid that it starts with letter ‘S’. [5]
d. Display the names who are both supplier as well as customer [10]
f. Create a view which displays Product ids and sum of quantity in sales [20]
g. Create a sequence named Product_Sequence that gets incremented by 10 and use it for
inserting Prodid values in Product table. [10]
h. Create a Trigger which reduces the stock of Product that is been inserted in sales and print
if it is out of stock (stock <Reord) [20]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
18. Consider the following relational schema for a Loan database application:
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’. [5]
e. Display the custid and Custname whose loan amount lies in the range of 30,000 to 50,000
[10]
f. Display the CustId and CustName who have taken less than 2 loans [10]
g. Create a view that keeps track of Custid, Custname, loanid and loan amount. [20]
h. Create a sequence named Customer_Sequence that gets incremented by 3 and use it for
inserting Custid values in Customer table. [10]
i. Develop a function named Customer_Loan which accepts Loanid as input and displays
Custid, CustName and loan_amount. [20]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
19. Consider the following relational schema for a Books Ordering database application:
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 [20]
c. Include the constraint on Cust_id that it starts with letter ‘C’. [5]
d. Display the custid and Custname who have ordered more than 3 books on the same date
[10]
e. Display the CustId and CustName who have ordered very few number of books. [10]
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]
g. Create a procedure named Books_Ordered which outputs the customer name, book
title and quantity ordered for the given order number [20]
h. In the above created procedure include exception to display “No such Order Number”
if incorrect order number is given. [10]
www.Vidyarthiplus.com
www.Vidyarthiplus.com
20. Consider the following relational schema for Products Order database application:
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 [20]
c. Include the constraint on orderid that it starts with letter ‘O’. [5]
d. Display the ProdID and the sum of quantity ordered for each product. [10]
e. Create a view that keeps track of P_id, price, order_id, qty_ordered and ordered_date.
[20]
h. Create a database TRIGGER, which deletes the order from Orders table, AFTER the
deletion of corresponding order_number in Order_details. [30]
www.Vidyarthiplus.com