1
I am trying to register a product in a cart, every time it is registered la significa q was purchased, so whenever this happens I want to decrease the amount in stock, tried with Trigger below, but it did not work:
DELIMITER $$
CREATE TRIGGER Tira BEFORE UPDATE
ON Carrinho
FOR EACH ROW
BEGIN
IF NEW.Carrinho.Produto = 198 THEN
UPDATE Produto SET QuantidadeEstoque = (QauntidadeEstoque - 1);
END IF;
IF NEW.Carrinho.Produto = 135 THEN
UPDATE Produto SET QuantidadeEstoque = (QauntidadeEstoque - 1);
END IF;
IF NEW.Carrinho.Produto = 244 THEN
UPDATE Produto SET QuantidadeEstoque = (QauntidadeEstoque - 1);
END IF;
IF NEW.Carrinho.Produto = 562 THEN
UPDATE Produto SET QuantidadeEstoque = (QauntidadeEstoque - 1);
END IF;
END $$
DELIMITER ;
This is the table:
I noticed an error in the word
QauntidadeEstoque
... would not beQuantidadeEstoque
?– Sam
corrected and changed nothing
– Nathan Silva
that’s right??
– Nathan Silva
nor I, have tried everything and not right, I started seeing these triggers today
– Nathan Silva
You want it to run as soon as a new cart is registered right?
– Thiagosilr
Nathan, can you post the structure of the tables you’re using? It’s easier to see the problem
– Clayton Tosatti
I can, I’ll put.
– Nathan Silva
this ai is the product table
– Nathan Silva