I want that after canceling a record in the tblingreso table the corresponding stock in the articles table is updated (the stock is subtracted):
UPDATE tblingreso SET estado='Anulado' WHERE idingreso='1';
I have my table tblingreso with the fields:
idIngreso int(11)
idProveedor int(11)
total decimal(14,4)
estado varchar(20)
With data it would be like this:
The detail table tbldetalleingreso:
iddetalleingreso int(11)
idingreso int(11)
idarticulo int(11)
cantidad int(11)
preciocompra decimal(14,4)
With data the tbldetalleingreso:
and the table tblarticle:
PS: I tried the following and I could not create the trigger:
DELIMITER //
CREATE TRIGGER tr_updStockAnular After update on tblingreso for each row
begin
update tblarticulo SET stock = stock - new.tbldetalleingreso.cantidad
where tblarticulo.idarticulo=new.tbldetalleingreso.idarticulo;
end
//
DELIMITER ;