Mysql
 SQL >> Base de Dados >  >> RDS >> Mysql

Criar trigger MySQL que atualiza outra tabela no INSERT

Em triggers, referencie campos com NEW. ou OLD.. Para inserir quantidade em estoque, use:

CREATE TRIGGER trg AFTER INSERT ON Product_Supply FOR EACH ROW UPDATE Product SET stock = stock + NEW.Supply_Quantity WHERE Product_ID = NEW.Product_ID;

NEW não existe em DELETE; OLD não existe em INSERT.