Creating a Trigger to Handle Product Restocking

Assignment Help PL-SQL Programming
Reference no: EM133043836

Assignment 9-1: Creating a Trigger to Handle Product Restocking

Brewbean's has a couple of columns in the product table to assist in inventory tracking. The REORDER column contains the stock level at which the product should be reordered. If the stock falls to this level, Brewbean's wants the application to insert a row in the BB_PRODUCT_REQUEST table automatically to alert the ordering clerk that additional inventory is needed. Brewbean's currently uses the reorder level amount as the quantity that should be ordered. This task can be handled by using a trigger.

1. Take out some scrap paper and a pencil. Think about the tasks the triggers needs to perform, including checking whether the new stock level falls below the reorder point. If so, check whether the product is already on order by viewing the product request table; if not, enter a new product request. Try to write the trigger code on paper. Even though you learn a lot by reviewing code, you improve your skills faster when you create the code on your own.

2. Open the c9reorder. . txt file in the Chapter09 folder. Review this trigger code, and determine how it compares with your code.

3. In SQL Developer, create the trigger with the provided code.

4. Test the trigger with product ID 4. First, run the query shown in Figure 9-36 to verify the current stock data for this product. Notice that a sale of one more item should initiate a reorder.

2322_Stock Information2.jpg

FIGURE 9-36 Checking stock data

5. Run the UPDATE statement shown in Figure 9-37. It should cause the trigger to fire. Notice the query to check whether the trigger fired and whether a product stock request was inserted in the BB_PRODUCT_REQUEST table.

1517_Stock Information3.jpg

FIGURE 9-37 Updating the stock level for product 4

6. Issue a ROLLBACK statement to undo these DML actions to restore data to its original state for use in later assignments.

7. Run the following statement to disable this trigger so that it doesn't affect other projects:
ALTER TRIGGER bb_reorder_trg DISABLE;

Assignment 9-2: Updating Stock Information When a Product Request Is Filled

Brewbean's has a BB_PRODUCT_REQUEST table where requests to refill stock levels are inserted automatically via a trigger. After the stock level falls below the reorder level, this trigger fires and enters a request in the table. This procedure works great; however, when store clerks record that the product request has been filled by updating the table's DTRECD and COST columns, they want the stock level in the product table to be updated. Create a trigger named BS_REQFILL_TRG to handle this task, using the following steps as a guideline:

1. In SQL Developer, run the following INSERT statement to create a product request you can use in this assignment:
INSERT INTO bb_product_request (idRequest, idProduct, dtRequest, qty) VALUES (3, 5, SYSDATE, 45);
COMMIT;

2. Create the trigger (BB_REQFILL_TRG) so that it fires when a received date is entered in the BB_PRODUCT_REQUEST table. This trigger needs to modify the STOCK column in the BB_PRODUCT table to reflect the increased inventory.

3. Now test the trigger. First, query the stock and reorder data for product 5, as shown in Figure 9-38.

885_Stock Information.jpg

FIGURE 9-38 Querying the data for product 5 stock and reorder amount

4. Now update the product request to record it as fulfilled by using the UPDATE statement shown in Figure 9-39.

1315_Stock Information1.jpg

FIGURE 9-39 Updating the product request Chapter 9

5. Issue queries to verify that the trigger fired and the stock level of product 5 has been modified correctly. Then issue a ROLLBACK statement to undo the modifications.

6. If you aren't doing Assignment 9-3, disable the trigger so that it doesn't affect other assignments.

Assignment 9-3: Updating the Stock Level If a Product Fulfillment Is Canceled

The Brewbean's developers have made progress on the inventory-handling processes; however. they hit a snag when a store clerk incorrectly recorded a product request as fulfilled.

When the product request was updated to record a DTRECD value, the product's stock level was updated automatically via an existing trigger, BB REQFILL TRG. If the clerk empties the DTRECD column to indicate that the product request hasn't been filled, the product's stock
level needs to be corrected or reduced. too. Modify the BB_REQFILL_TRG trigger to solve this problem.

1. Modify the trigger code from Assignment 9-2 as needed. Add code to check whether the DTRECD column already has a date in it and is now being set to NULL.

2. Issue the following DML actions to create and update rows that you can use to test the trigger:

INSERT INTO bb product request (idRequest, idProduct, dtRequest, qty, dtRecd, cost)
VALUES (4, 5, SYSDATE, 45, ' 15-JUN-2012 ' 225) ;
UPDATE bb product
SET stock = 86
WHERE idProduct = 5;
COMMIT;

3. Run the following UPDATE statement to test the trigger, and issue queries to verify that the data has been modified correctly.
UPDATE bb product request SET dtRecd = NULL
WHERE idRequest = 4;

4. Be sure to run the following statement to disable this trigger so that it doesn't affect other assignments:
ALTER TRIGGER bbreqfilltrg DISABLE;

Assignment 9-4: Updating Stock Levels When an Order Is Canceled

At times, customers make mistakes in submitting orders and call to cancel an order. Brewbean's wants to create a trigger that automatically updates the stock level of all products associated with a canceled order and updates the ORDERPLACED column of the BB_BASKET table to zero, reflecting that the order wasn't completed. Create a trigger named BB ORDCANCEL TRG to perform this task, taking into account the following points:
• The trigger needs to fire when a new status record is added to the BB_BASKETSTATUS table and when the IDSTAGE column is set to 4,
which indicates an order has been canceled.
• Each basket can contain multiple items in the BB_BASKETITEM table, so a CURSOR FOR loop might be a suitable mechanism for updating each item's stock level.
• Keep in mind that coffee can be ordered in half or whole pounds.
• Use basket 6. which contains two items, for testing.

1. Run this INSERT statement to test the trigger:
INSERT INTO bbbasketstatus (idStatus, idBasket, idStage, dtStage) VALUES (hi:Ls t atuss eq NEXTVAL 6, 4, SYSDATE) ;

2. Issue queries to confirm that the trigger has modified the basket's order status and product stock levels correctly.

3. Be sure to run the following statement to disable this trigger so that it doesn't affect other assignments:
ALTER TRIGGER bbordcanceltrg DISABLE;

Reference no: EM133043836

Questions Cloud

Coordinating the corporate compensation : The compensation and benefits manager plays a vital role in coordinating the corporate compensation and benefits department. With reference to theory and exampl
Common problems that employee assistance program : Briefly explain any FIVE (5) the common problems that an Employee Assistance Program (EAP) can address in the organisation. Use relevant examples to substantiat
How much is the revenue to be recognized on this contract : Emerald Corporation sold a set of washing machine and a dryer for a total contract price of P200,000. How much is the revenue to be recognized on this contract
Examine the main goals of the compensation department : The compensation and benefits manager plays a vital role in coordinating the corporate compensation and benefits department.
Creating a Trigger to Handle Product Restocking : Creating a Trigger to Handle Product Restocking and Updating Stock Information When a Product Request Is Filled
Why is it important to validate information : 1) Why is it important to validate Information?
Prepare the january journal entry to record bond issuance : Hillside issues $1,700,000 of 8%, 15-year bonds dated January 1, 2020, Prepare the January 1 journal entry to record the bonds' issuance
Traditional methods ineffective : What factors would make these traditional methods effective? What factors would make these traditional methods ineffective?
Make traditional methods ineffective : What factors would make these traditional methods effective? What factors would make these traditional methods ineffective?

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Create a database model

Create a database model and Submit the table creation statements for the Database Model.

  Write pl-sql procedures and functions

Write PL/SQL procedures and functions to populate and query that database

  Sql questions

Write a query to display using the employees table the EMPLOYEE_ID, FIRST_NAME, LAST_NAME and HIRE_DATE of every employee who was hired after to 1 January, 1995.

  Run the lab_03_01.sql script

Run the lab_03_01.sql script in the attached file to create the SAL_HISTORY table. Display the structure of the SAL_HISTORY table.

  Write sql queries

Write a query to display the last name, department number, and salary of any employee whose department number and salary both match the department number and salary of any employee who earns a commission.

  Explaining sql insert statement to insert new row in cds

Write down a SQL insert statement to insert new row in "CDS" table.

  Write down name of actors in ascending order

Write down actors (or actress, your choice, but not both) who have won at least two (2) Academy Awards for best actor/actress. Provide the actor name, movie title & year. Order the result by actor name."

  What is an sql injection attack

What is an SQL injection attack? Explain how it works, and what precautions must be taken to prevent SQL injection attacks.What are two advantages of encrypting data stored in the database?

  Determine resonant frequency in series rlc resonant circuit

Given the series RLC resonant circuit in the figure, operating at variable frequency, determine: The resonant frequency ω o ,  The circuit’s quality factor Q , The cut-off frequencies, f 1  & f 2  and the bandwidth BW

  Query that uses cube operator to return lineitemsum

Write summary query which uses CUBE operator to return LineItemSum (which is the sum of InvoiceLineItemAmount) group by Account(an alias for AccountDesciption).

  Query to show customers were missing for existing orders

As DBA, your manager called a meeting and asked why there are so many orders for customers that don't exist in the customer table. Write query which would shows which customers were missing for existing orders. Use a join or a subquery.

  Sql query into a relational algebra statement

Turn this SQL query into a relational algebra statement? SELECT Request.reqfor, Ordering.invamt, Ordering.invnbr, Ordering.invdat

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd