Create a trigger named trg_line_prod that automatically updates the quantity on hand for each product sold after a new LINE row is added.

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter8: Working With Advanced Functions
Section: Chapter Questions
Problem 4.4CP
icon
Related questions
Question

Hello, I have a few questions in regards to MYSQL. It was answered on the website before, but whenever I put the answer in my IDE I get a syntax error, so I will ask here instead for the few I need help with. The topic is MySQL triggers.

 

The second question (or task) is as follows: 

"Create a trigger named trg_line_prod that automatically updates the quantity on hand for each product sold after a new LINE row is added."

 

An in-depth explanation is appreciated, thank you for your time.

The table attached contains the database schema: 

Expert Solution
Step 1

Trigger:

The trigger is a named set of SQL statement that is executed at the time of data modification or meets some data description.

  • If the stated trigger condition meets up, then the mentioned action in the trigger has been performed. There are three parts of trigger; they are:

Event:

  • It specifies the change to be made, such as an UPDATE or DELETE of a record. Condition:
  • It specifies the condition to examine the records about to be affected. For each record, that meets the condition given in the trigger.

Action:

  • The action performed after the start of the trigger.

Computer Science homework question answer, step 1, image 1

 

Step 2

Query to create trigger:

CREATE OR REPLACE TRIGGER TRG_LINE_PROD

AFTER INSERT ON LINE

FOR EACH ROW

BEGIN

UPDATE PRODUCT SETP_QOH = P_QOH - :NEW.LINE UNITS

WHERE PRODUCT.P_CODE = :NEW._CODE:

END;

/

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning