Create a trigger for the Invoices table that automatically inserts the vendor na
ID: 3938820 • Letter: C
Question
Create a trigger for the Invoices table that automatically inserts the vendor name and address for a paid invoice into a table named ShippingLabels. The trigger should fire any time the PaymentTotal column of the Invoices table is updated. The structure of the ShippingLabels table is as follows:
CREATE TABLE ShipplingLabels (
VendorName varchar(50), VendorAddress1 varchar(50), VendorAddress2 varcha(50), VendorCity varchar(50), VendorState varchar(2), VendorZipcode Varchar(20) )
Use the UPDATE statement to test the trigger: UPDATE Invoices SET PaymentTotal = 67.92, PaymentDate = ‘2008-08-23’ WHERE InvoiceID = 100
Explanation / Answer
CREATE OR REPLACE TRIGGER AFTER_UPDATE_PAYMENTTOTAL
AFTER UPDATE of paymentTotal ON Invoices
FOR EACH ROW
BEGIN
INSERT INTO ShipplingLabels VALUES
('VendorName','VendorAddress1','VendorAddress1','City','State','Zipcode');
END;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.