0% found this document useful (0 votes)
10 views1 page

LabTerminal BCEA

Uploaded by

Ali Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

LabTerminal BCEA

Uploaded by

Ali Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

COMSATS University Islamabad, Lahore Campus

Department of Electrical and Computer Engineering

Terminal Lab Examination – Fall 2024


Course Title: Databases-1 Course Code: CSC 371 Credit Hours: 4(3,1)
Course Instructor: Modassir Ishfaq Programme Name: BCE
Semester: N/A Batch: Fa22 Section: B Date: 18-12-2024
Time Allowed: 90 Minutes Maximum Marks: 30
Student’s Name: Reg. No. CUI/…………………………../LHR
Important Instructions / Guidelines:
• Write all queries (commented with mentioned task numbers) in a single script file
• Save the final file as FaXX-BCE-XXX.sql
• Email to [email protected]

Question (30 Marks)

Refer to the following relational schema:


Orders (orderID,customerID,productID, orderSTATUS, quantity, totalvalue)
Customers(customerID, customerName )
Products(ProductID, ProductName, quantity, pp_price)

A. Create a trigger on the Products table to automatically log an entry into a Stock_Audit table whenever a
product’s name, quantity or price is updated. The trigger should capture the ProductID, updated attribute,
old_value, new value, and Timestamp.
(4)
B. Write a query to display the customers who placed more than three orders, along with the total value of their
orders. Displayed data should be as : OrderID | Customer name | Product NAME | Total Value
(4)
C. Using a correlated subquery, retrieve details of the products that have been sold at least once and provide the sale
count as well
(4)
D. Write a stored procedure that accepts customerID as an input and returns:
a. Total Orders placed by the customer
b. Total Value of the orders
c. The most frequently purchased product by the customer
(4)
E. Create a view named OrderSummary that displays data as:
OrderID | Customer Name | Product Name | OrderedQuantity | Order Status | Total Bill
(4)
F. Ensure that the view OrderSummary supports direct updates to the OrderedQuantity in orders table. e.g.
UPDATE OrderSummary
SET OrderedQuantity = 10
WHERE OrderID = 1;
(4)
G. Implement a transaction to maintain consistency between Orders and Products such that:
a. when a new order is placed, it must check if the requested quantity is available or not.
b. If requested quantity exceeds available quantity, transaction must be rolled back with a custom prompt
message.
c. In case if sufficient stock is available, deduct the requested quantity from available stock, calculate the total
value as per the price mentioned in the products table and insert the order accordingly.
d. Utilize the trigger created in (A) to log entry in the Stock Audit table as well.
(6)

You might also like