Update stock levels when the order is cancelled

Assignment Help PL-SQL Programming
Reference no: EM13201661

Question 1. Update stock levels when the order is cancelled

At times, customers make mistakes in submitting their orders and call to cancel the order. Brewbean's wants to create a trigger that automatically updates the stock level of all products associated with a cancelled order and that updates the ORDERPLACED column of the BB_BASKET table to zero, reflecting that the order was not completed. Create a trigger named BB_ORDERCANCEL_TRG to accomplish this task by considering the following items:

  1. 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 order cancellation.
  2. Each basket can contain multiple items in the BB_BASKETITEM table, so a CURSOR FOR loop may be an appropriate mechanism to update the stock level of each item.
  3. Keep in mind that coffee can be ordered in half o whole pounds.
  4. Use basket 6 for testing. Note that this basket contains two items.
    1. Open or return to SQL Plus. Execute the following statement to test the trigger:

Insert into bb_basketstatus (idstatus, idbasket, idstage, tdstage) values (bb_status_seq.nextval, 6, 4, sysdate);

  1.  
    1. Execute queries to confirm that the basket order status and product stock levels have been appropriately modified by the trigger.
    2. Be sure to run the following statement to disable this trigger so that it does not affect other products:

Alter trigger bb_ordcancel_trg disable;

Question 2. Process discounts

Brewbean's is implementing a new discount for return shoppers - every fifth completed order receives a 10% discount. The count of orders for a shopper is placed in a packaged variable named PV_DISC_NUM during the ordering process. This count needs to be tested upon checkout to determine if a discount should be applied. Create a trigger named BB_DISCOUNT_TRG so that when an order is confirmed (the ORDERPLACED value is set from 0 to 1), the PV_DISC_NUM packaged variable is checked. If it is equal to 5, then set a second packaged variable named PV_DISC_TXT to 'Y'. This variable is used in calculating the order summary so that a discount is applied if appropriate.

Create a package specification named DISC_PKG that contains the needed packaged variables. Use an anonymous block to initialize the packaged variables to use for testing the trigger. Test the trigger by using the following update statement:

Update bb_basket set orderplaced =1 where idbasket=13;

Reset the ORDERPLACED to zero for the basket used (this is done as needed to complete trigger testing). Also, disable this trigger when completed so that it does not affect other assignment questions.

Question 3. Use triggers to maintain referential integrity

At times, Brewbean's has changed the id number for existing products. In the past, they have had to add a new product row with the new id to the BB_PRODUCT table, modify all the corresponding BB_BASKETITEM and BB_PRODUCTOPTION table rows, and then delete the original product row. Can a trigger be developed to avoid all these steps and handle the update of the BB_BASKETITEM and BB_PRODUCT OPTION table rows automatically for a given change in product id? If so, create the trigger and test by issuing an update statement, which changes the IDPRODUCT of 7 to 22. Do a rollback to return the data back to its original state. Also, disable the new trigger after you have completed the assignment.

Question 4. Maintain an audit trail of product table changes

The accuracy of product table data is critical and the Brwebean's. owner wants to have an audit file that contains information regarding all DML activity on the BB_PRODUCT table. This information should indicate the user id of the user running a DML statement, the date, the original values of the changed rows and the new values. The audit table needs to track specific columns of concern, including PRODUCTNAME, PRICE, SALESTART, SALEEND, and SALEPRICE. Create a table named BB_PRODCHG_AUDIT that can hold the relevant data. Then create a trigger named BB_AUDIT_TRG that fires on update to this table whenever one of the specified columns in the BB_PRODUCT table is changed.

Use the following update statement to test your trigger. Then, complete a rollback and disable the trigger when completed so that it does not affect other assignment questions.

Update bb_product set salestart = '05-MAY-03', saleend = '12-MAY-03', saleprice = 9 where idproduct = 10;

1134_Database Schema.jpg

Download:- PLSQL.rar

Reference no: EM13201661

Questions Cloud

Explain what is the inverse demand function : Ajax, Inc. is a monopolist. The estimated demand function for its product is Qd = 120 - 0.8P + 12Y + 4A Where Qd denotes quantity demanded, P denotes price, Y denotes personal income (in thousands of dollars), and A denotes advertising expenditures
Administrator and teacher interview : Why did you choose to go into education as a career? Would you recommend the education profession to others? Why or why not? Are there any other teachers in your family? If so, who?
Solve the equation to find the total monthly cost : The equation C=mx+b can be used to model the monthly cost, C, of a cell phone plan where b is the flat monthly cost, m represents the cost in dollars per minute and x is the number of minutes used in the month.
Under what conditions would use both types of tobacco : If you were a tobacco farmer and had two loads of tobacco that were of different qualities, which would you supply as money and which would you supply for smoking.
Update stock levels when the order is cancelled : Execute queries to confirm that the basket order status and product stock levels have been appropriately modified by the trigger - the trigger needs to fire when a new status record is added to the BB_BASKETSTATUS table and when the IDSTAGE col..
Identify the casual hypothesis at issue : “In the fifty-seven-month study, whose participants were all male physicians, 104 of those who took aspirin had heart attacks, as compared with 189 heart attacks in those who took only a sugar pill. This means ordinary aspirin reduced the heart attac..
Explain the life expectancy of people in asia : A sociologist wants to determine if the life expectancy of people in Africa is less than the life expectancy of people in Asia. The data obtained is shown in the table below.
Analyze reported crime statistics for offense categories : Select a city, town, or municipality and examine trends in criminal activity over the last 3 years. Analyze reported crime statistics for major/minor offense categories such as murder, robbery, rape, and create a table of the results.
Find the total cost to paint all the six sides : A cubical tank with side 8.9 feet is to be painted. It costs $2 per square feet to paint. Find the total cost to paint all the six sides.

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Produce a diagram showing schema

Produce a diagram showing schema and the partial and transitive dependencies in your 1NF. b. Produce a diagram showing table schema and any transitive dependencies in your 2NF

  Relational schema of a firm database - write a sql query

Display the vendor ID and vendor name of the items whose item quantity is the largest and display the item ID and item quantity of all items whoseitem quantity is less than the average quantity. Also display the average quantity

  Calculate days between ordering and shipping

Calculate the Tax on an Order, Calculate the Total Shopper Spending - Develop a SELECT statement using the BB_SHOPPER table to produce a list of each shopper in the database and his or her respective totals.

  Write command to list all the employees in year

Write the command to list all the employees hired in 2003 and 2004. Sort the rows by the hire_date column in descending order.

  Write sql statement to produce single column

Write an SQL statement to produce a single column called ItemLocation that combines the SKU_Description,the phrase "is located in."

  Write sql statement to create stored procedure

Write SQL statement which creates stored procedure with one int input parameter. The stored procedure selects the supplierId field and the total of all Count field values for each group of supplierId's from the Part table.

  Commands that you would use to create a 7x7 matrix

Show the unix/linux commands that you would use to create a 7x7 matrix of alternating entries of 1's and 0's. It should look like this

  Create student sorting table

Student.txt in the attachment contains the roster of a class. Each student object has the following fields: student id, last name, first name, academic level.Create a RosterClass to store the student database in vector.

  Write a select statement that returns these columns

Write a SELECT statement that returns these columns from the Products table: The date_added column A column that uses the CAST function to return the date_added column with its date only (year, month, and day)

  Provide four queries to answer questions asked by end users

Explain how you will go about developing this database. Provide at least four queries that answer some of the questions asked by the end users.

  Script that creates and calls a stored

Write a script that creates and calls a stored procedure named spInsertProduct that inserts a row into the Products table. This stored procedure should accept five parameters

  Write pl-sql block to display the last name of people

Write a PL/SQL block that displays the last name and salary of the following people. Each of these can be done separately as PL/SQL, first to test and get the output lines then encapsulated in the procedure.

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