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

Adv SQL Exercise2

The document describes creating tables and inserting sample data, and writing triggers on those tables. It instructs to create triggers on the Ord_dtl and Ord_mst tables that update the Booked_qty in the Prod_mst table when rows are inserted, deleted, or updated in Ord_dtl. It also describes a trigger on Ord_mst that decreases Booked_qty and Qty_in_stock or cancels the order if the status is updated.

Uploaded by

Nishant Andhale
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views1 page

Adv SQL Exercise2

The document describes creating tables and inserting sample data, and writing triggers on those tables. It instructs to create triggers on the Ord_dtl and Ord_mst tables that update the Booked_qty in the Prod_mst table when rows are inserted, deleted, or updated in Ord_dtl. It also describes a trigger on Ord_mst that decreases Booked_qty and Qty_in_stock or cancels the order if the status is updated.

Uploaded by

Nishant Andhale
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Adv.

SQL Exercise 2
Create the following 3 tables and insert sample data as shown:Ord_mst Ord_no 1 C1 Ord_dtl Ord_no 1 1 Prod_mst Prod_cd P1 P2 P3 Cust_cd P Prod_cd P1 P2 Prod_name Floppies Printers Modems Status

Qty 100 200 Qty_in_stock 10000 5000 3000 Booked_qty 1000 600 200

1. Write a Before Insert trigger on Ord_dtl. Anytime a row is inserted in Ord_dtl, the Booked_qty in Prod_mst should be increased accordingly. 2. Write a Before Delete trigger on Ord_dtl. Anytime a row is deleted from Ord_dtl, the Booked_qty in Prod_mst should be decreased accordingly. 3. Write a Before Update of Prod_cd, Qty trigger on Ord_dtl. Anytime the Prod_cd or Qty is updated, the Booked_qty in Prod_mst should be increased/decreased accordingly. 4. Write a Before Update of Status trigger on Ord_mst. If the Status is updated from P (Pending) to D (Delivered), the Booked_qty and Qty_in_stock from Prod_mst should be decreased accordingly. If the Status is updated from P (Pending) to C (Cancelled), the details of the order should be deleted from Ord_dtl and corresponding Booked_qty from Prod_mst should be decreased accordingly. (The Before delete trigger on Ord_dtl would automatically decrease the Booked_qty from Prod_mst).

Sameer Dehadrai

Page: 1

You might also like