Execute queries to confirm that the basket order status

Assignment Help PL-SQL Programming
Reference no: EM13204718

Use the provided appbDbcreate.sql SQL script to create the database to be used when working on this assignment.

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. 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;

Reference no: EM13204718

Questions Cloud

How many more kilometers must be driven : after driving 164 km 4/7 of the trip is completed. how long is the trip? how many more kilometers must be driven.
What is the magnitude of the tension on the ends : What is the magnitude of the tension on the ends of the clothesline?
Understanding contemporary social and economic change : What is the usefulness of the Rostow model in understanding contemporary social and economic change with reference to A country's role in the world economy, colonial transportation networks, cultural differences, local social and class structures exa..
Many solutions are there in nonnegative integers to equation : many solutions are there in nonnegative integers to the equation x1 +x2 + · · · + xm = r, where m and r are constants?
Execute queries to confirm that the basket order status : Execute queries to confirm that the basket order status and product stock levels have been appropriately modified by the trigger.
When rms will confront decreasing returns to scale : Economists classify production functions as possessing constant, decreasing or increasing returns to scale. Yet, from a cause-and-effect point of view, it is not readily apparent why decreasing returns to scale should ever exist. That is, if we du..
Affected global domination and stratification : How has the introduction of new technologies affected global domination and stratification?
Find the pair of integers that satisfies this condition : The product of two consecutive positive odd integers is 143. Find the pair of integers that satisfies this condition.
Affect the increase in social security and other benefits : A newspaper article written by the Associated Press reported that the US economy was expecting a low rate of inflation. It said that “low inflation has a downside:

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Write a script that declares a variable

Write a script that declares a variable and sets it to the count of all products in the Products table. If the count is greater than or equal to 7, the script should display a message that says,

  Script that creates and calls a function named

Write a script that creates and calls a function named fnDiscountPrice that calculates the discount price of an item in the OrderItems table (discount amount subtracted from item price). To do that, this function should accept one parameter for th..

  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

  Select statement to return one row

Write a SELECT statement that returns one row for each general ledger account number which contains three columns.

  Write down sql needed to create employee table

Write down SQL needed to create employee table containing the following data: employeeID, text, length of 5, primary key lastName, text, length of 25

  Write queries in sql and relational algebra

Write given queries in SQL and relational algebra: Determine cities from which one can fly to Toronto with one change of planes, and using same type of the aircraft for both legs of trip.

  Decomposition for r = (a,b,c,d,e )

Give a good decomposition for R = (A,B,C,D,E ) with the following functional dependencies:

  Script that creates and calls a function

Write a script that creates and calls a function named fnItemTotal that calculates the total amount of an item in the OrderItems table (discount price multiplied by quantity)

  Create report to display scr courses in alphabetical order

Create the detail report which will display all SCR courses in alphabetical order, with a course name and instructor name in the group header.

  The cast function to return the date added column

A column that uses the CAST function to return the DateAdded column with its full time only (hour, minutes, seconds, and milliseconds)

  Write an update statement that modifies the row

Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the ProductName column to "Woodwinds", and it should use the CategoryID column to identify the row.

  Display the customerid from the orders table

Display the CustomerID from the Orders table and the sum of the associated ItemPrice multiplied by Quantity using Gross Sales (with a space) as the column name from the OrderItems table.

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