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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education