Related questions
Concept explainers
EXAMINE THE TRIGGER BELOW IS IT CORRECT? IF NOT MODIFY
Create test to show that the triggers are correctly implemented, do the following:
-
Truncate the Transaction table
-
Reset the Tx_Nbr sequence back to 1
-
Update the Account table, setting the Balance back to zero
-
Re-run the INSERT statements for the transactions
-
Use simple queries to demonstrate that the results in the Transaction and Account tables are as expected
GIVEN THE TRIGGER BELOW:
- Trigger to enforce the referential integrity for the Transaction Ref_Nbr:
- Deposit or Withdrawal transaction to Bank Branch
- Bill Payment, Debit Purchase, or Return transaction to Merchant
CREATE TRIGGER Transaction_RefNbr_Check
BEFORE INSERT OR UPDATE ON Transactions
FOR EACH ROW
DECLARE
TxRefNbr_count INTEGER;
BEGIN
IF:NEW.TxTypeCode = ‘D’ OR :NEW.TxTypeCode = ‘W’ THEN
SELECT COUNT(*)INTO TxRefNbr_count
FROM BRANCH
WHERE BranchNbr=:NEW.RefNbr;
IF TxRefNbr_count = 0 THEN
RAISE_APPLICATION_ERROR(-20000, ‘Invalid Branch Number’);
END IF;
ELSIF: NEW.TxTypeCode=‘B’ OR :NEW.TxTypeCode=‘P’ OR :NEW.TxTypeCode=‘R’THEN
SELECT COUNT(*)INTO TxRefNbr_count
FROM MERCHANT
WHERE BranchNbr=:NEW.RefNbr;
IF TxRefNbr_count = 0 THEN
RAISE_APPLICATION_ERROR(-20000, ‘Invalid Merchant Number’);
END IF;
END IF;
END;
- Trigger to update the Account balance for each new transaction entered (assume that a transaction will never be updated or deleted).
CREATE OR REPLACE TRIGGER UpdateAccountBalance
AFTER INSERT ON Transactions
FOR EACH ROW
BEGIN
UPDATE Account SET Balance= Balance+:NEW.TxAmount
WHERE AccountNbr=:NEW.AccountNbr;
END;
Step by stepSolved in 2 steps
- Sales Database: Customers(custId, lastName, firstName, address, phone, creditLimit) Orders(ordNumber, itemNumber, qtyOrdered.) Items(itemNumber, itemName, price) For the Sales Database referenced above, write the SQL command to create the LineItem table, assuming the Orders table and items table already exist.arrow_forwardThe database contains a Horse table, with columns: ID integer, primary key Registered Name variable-length string. The database contains a Student table, with columns: • ID integer, primary key First Name - variable-length string LastName variable-length string Write a SQL Query to create a Schedule table, with columns: HorseID - integer with range 0 to 65535, not NULL • Student ID integer with range 0 to 65535 Lesson DateTime - date/time, not NULL (HorseID, Lesson DateTime) is the primary key Also, create the following foreign key constraints on Schedule columns: HorseID references Horse. When an ID is deleted from Horse matching Lesson Schedule rows are deleted. Student ID references Student. When an ID is deleted from Student, matching Student ID 's are set to NULL).arrow_forwardTask 8: Create the UPDATE_INVOICE procedure to change the date of the invoice whose number is stored in I_INVOICE_NUM to the date currently found in I_INVOICE_DATE.arrow_forward
- Q2:Write a row-level trigger that executes before updating a project’s location in the project table. The trigger changes the department number of the project to 4 if the location is in ‘Stafford’. SQLarrow_forwardTask 9: Create the DELETE_INVOICE procedure to delete the invoice whose number is stored in I_INVOICE_NUM.arrow_forwardTrigger pleasearrow_forward
- My other instruction for SQL says: Create and test a stored procedure called checkin_transaction that processes a "checkin" transaction. When a book is checked in, the corresponding CHECKOUT record is updated to show the date it was checked in, and the Pat_ID attribute in the BOOK table is updated to NULL. The entire transaction (starting with START TRANSACTION; and ending with COMMIT;) should be in between the BEGIN and END statements of the stored procedure. You should be able to call the procedure with a statement like this, passing the values of the Book_Num, Pat_ID, and Check_In_Date to the procedure: CALL checkin_transaction(5243, 1170, ‘2017年04月30日’) Do you guys know how?arrow_forwardWrite a stored procedure named updateUnitsOnOrder(). The updateUnitsOnOrder ()procedure should update the UnitsOnOrder field of those products that are discontinued. It should set the UnitsOnOrder field to 99 for those discontinued products. Hint: There is no need to use cursor processing for this stored procedure.arrow_forwardCreate table statements (file name must be: 1_create_table.txt). Make sure you specify primary keys and foreign keys. Specifying "not null" constraint is optional. Specifying "on delete action" and "on update action" are optional.arrow_forward
- The activation of one trigger may result in the activation of another trigger. True Falsearrow_forwardTask 3: The Marketing team wants to collect emails of the users on InstantStay. However, the team needs a SQL statement to execute inside their programming environment. You need to create a statement that they can easily run the EXECUTE command to return a single column table containing the USER_EMAIL addresses. Task: Create a prepared statement for use with the EXECUTE command.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education