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

  Statement to display the sku, sku_description

write an sql statement to display the SKU, SKU_Description, WareHouse ID, and QuantityOnHand for all products having a QuantityOnOrder equal to 0. Sort the results in descending order by WareHouse ID and in ascending order by SKU

  Provide a comprehensive record of using sql

Learning Objectives: The purpose of Project 3 is to enable the students to gain extensive experience with using SQL to design and query databases.

  DBS201 Database Application Development Assignment

DBS201 Database Application Development Assignment Help and Solution, Seneca College - Assessment Writing Service - create a simple HR application.

  Define exception handlers in programming

Add exception handlers for errors that you can and cannot anticipate. Test the block by running it with various values of the host variable.

  Differentiate between updatable and non updatable

What do you mean by 'view'? What are its different types? Differentiate between updatable and non updatable 'view' with suitable examples. Also give proper syntax for creating 'view'.

  Suggest two sql optimization techniques that can be used

Suggest at least two SQL optimization techniques that can be used to enhance the data access turnaround time and transaction processing time.

  Create a view named customer addresses

Create a view named CustomerAddresses that shows the shipping and billing

  What does each allow or restrict

Roles and Profiles are used by Oracle to define and control access and privileges of groups of users. Compare and contrast the concepts of role and profile.

  What three ways for identifying a dbms should nathan cover

Nathan is planning to describe at least three ways a database management system can be identified. What three ways for identifying a DBMS should Nathan cover?

  Develop and run a create function statement

Create a procedure named DDPAY_SP that identities whether a donor currently has an active pledge with monthly payments. A donor ID is the input to the procedure

  What types of sql-injection attack has been identified

What will be the impact of SQL-Injection attack and your recommendation to prevent those attacks - What types of Cross-side Scripting issues has been identified

  Create a table that includes a rotating schedule

M8A2 Short Paper: Evaluating a Database for Security Problems - Create a table that includes a rotating schedule for the 12 months of auditing

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