Hello, I created a trigger that every time the user makes a sale is debited the amount of items, but if I do not take care the amount can be negative because the user can sell more than he has in the database. So I need a trigger that does not INSERT that sale if the amount of the sale is greater than the one available. For this 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