Question 1 update stock levels when the order is

Assignment Help PL-SQL Programming
Reference no: EM13381105

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: EM13381105

Questions Cloud

For numbers 1-3 simplify assume all variables represent : for numbers 1-3 simplify. assume all variables represent positive real numbers4 add or subtract as indicated. assume
Assignments requirement1 support your assertions with at : assignments requirement1. support your assertions with at least two citations in apa format.2. acceptable sources
Create a financial analysis report of ge general electric : create a financial analysis report of ge general electric including the following six sections- executive summary-
Identify two firms with similar problems but from different : identify two firms with similar problems but from different countries. conduct a comparative analysis of the firms.
Question 1 update stock levels when the order is : question 1. update stock levels when the order is cancelledat times customers make mistakes in submitting their orders
Question 1 calculate the tax on an ordercomplete the : question 1. calculate the tax on an ordercomplete the following steps to create a procedure to calculate the tax on an
Training kitchen installationactivity 1- monitoringyou are : training kitchen installationactivity 1- monitoringyou are two weeks into your project. the project sponsor would
Part 1product maintenanceyoull create a series of pages : part 1product maintenanceyoull create a series of pages that allow you to add update or delete a product thats
Introduction to businessthis assignment requires that you : introduction to businessthis assignment requires that you demonstrate that you canbullunderstand business theory and

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Write the sql ddl to create the database

Write a command that will remove the Jones that lives in Orange from the Customer table .Write the SQL DDL to create the database that contains each of the relations shown in the above ERD.

  Business transaction that involves multiple tables

Write a business transaction that involves multiple tables and implement it using PL/SQL. Use at least one Function or Procedure in your code. The transaction may retrieve data from the database and display the result, or it may insert/update data in..

  Write pl-sql block which displays last name

Write PL/SQL block which displays last name and salary of following people. Each of these can be done separately as PL/SQL, first to test and get output lines

  Question 1 calculate the tax on an ordercomplete the

question 1. calculate the tax on an ordercomplete the following steps to create a procedure to calculate the tax on an

  Create a text file called yourstudentid

Create a text file called YourStudentId-Create.sql (format xxxxxxx-Create.sql) for example 2225991- Create.sql that will.

  Write sql statement to create view

Write a SQL Statement to create a View called vwEmployeeTerritories that will do the following: Return all Employees and their Territories (use INNER JOIN).

  Review problem and run required statement to create table

Please note that for "Table Employees" due to length of the table description and page size limit, I have broken it into 2 parts for better visibility, please make sure to use all the given attributes from the table.

  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)

  Write sql statement to add new record to part table

Write SQL statement which creates the stored procedure which adds new record to the Part table, and returns value of newly created PartID PK value in out parameter.

  Create the tables for the project

drop the tables you are creating (in case they've already been created within the schema I'm using).

  Compare and contrast the three phases of database design

Write an SQL select statement to list all double or family rooms with a price less than $255 per night in ascending order of price.

  Write queries in sql if employee works on every project

Write the following queries in SQL: If an employee works on every project located in Houston, then list the employees social security number and name.

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