Answer the question
In order to leave comments, you need to log in
How, when updating one value in the table, to update another, so that the updated value is a number with -10 from the first?
I don’t know how to formulate correctly in MySql I don’t understand well.
Given :
The test_table table has columns id_product , quantity and quantity_stock - everywhere Integer
Needed :
So that when the quantity column is updated , the quantity_stock column takes the value = the new value of the quantity column - 10
That's all that was enough for me, and apparently I don't understand anything :
CREATE TRIGGER update_test AFTER UPDATE ON test_table
FOR EACH ROW
BEGIN
IF NEW.quantity <=> OLD.quantity THEN
UPDATE test_table SET quantity_stock = NEW.quantity - 10;
END IF;
END;
Answer the question
In order to leave comments, you need to log in
Change the trigger to BEFORE UPDATE and just set the new value before the change.
CREATE TRIGGER update_test BEFORE UPDATE ON test_table
FOR EACH ROW
BEGIN
IF NEW.quantity <> OLD.quantity THEN
SET NEW.quantity_stock = NEW.quantity - 10;
END IF;
END;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question