1 Trigger Figure 162 Text Copy Run Trigger Created Ap Database Run Update Test Notice Two Q37075310

1. This trigger is from Figure 16.2 ofthe text. Copy and run this trigger so it is created in the apdatabase. You can run the UPDATE below to test it. Notice twothings. The error message appears as a pink screen just like asyntax error would. Also, if you then query the invoices table, theUPDATE statement did not execute. The trigger prevented theerroneous UPDATE from changing the data.

               

DELIMITER //

CREATE TRIGGERinvoices_before_update

   BEFOREUPDATE ON invoices

   FOREACH ROW

BEGIN

  DECLARE sum_line_item_amount DECIMAL(9,2);

   SELECTSUM(line_item_amount)

      INTO sum_line_item_amount

   FROMinvoice_line_items

   WHEREinvoice_id = NEW.invoice_id;

  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.