3
Hello, I created a Rigger that every time the user performs a sale is made the debit in the quantity of items, but if I do not take care the quantity can be negative because the user can sell more than they have in the database. So I need a Rigger who doesn’t do the INSERT of that sale if the amount of the sale is greater than available. For that I would need to test before... I started something like this
--Esse é um trigger BEFORE INSERT
BEGIN
set @qtd = SELECT itens.quantidade WHERE itens.id = NEW.itens_id;
IF (NEW.quantidade > @qtd) THEN
--Cancela o INSERT para que o Trigger do AFTER INSERT n faça a subtração ficando negativa no estoque
END IF;
END
I would do as you said in example 1.
– PauloHDSousa