Trigger updating a table

时间:2017-04-10 00:19:26

标签: mysql triggers

I have a trigger here that supports inserting an 'invoice' into my database, but I want it to automatically update the 'customer' in the 'customer' table by adding this new invoice to the customer's balance which is CUS_BALANCE Here is my trigger so far:

CREATE TRIGGER `invoice` BEFORE INSERT ON `invoice` 
FOR EACH ROW INSERT INTO invoice VALUES (customer, invoice, line, product, 
vendor);

1 个答案:

答案 0 :(得分:0)

Provide an update statement inside the trigger or call a stored proc with parameters to update the customers balance from the trigger.

delimiter //
create trigger invoice_trigger before insert on invoice
for each row 
begin 
Update customers set balance = new.balance where id = new.id
end //
delimiter ;