I have a table usuario
, with a record called jose whose status is user_state = 0
and I want the status to be 1
when there is an update in the information.
I'm not sure if what I need is a trigger or a stored procedure.
CREATE TRIGGER onUpdate
AFTER UPDATE ON user
UPDATE user
SET user_state = 1
WHERE iduser = ?;
That is the query I have but how do I get the id of the updated record?
You should use
BEFORE UPDATE
y assign withNEW
state in1
. It would be as follows:With the word
NEW
you refer to the current record and withBEFORE
before saving.With the trigger is enough, just reference it with the NEW keyword:
SET NEW.user_state = 1;
The UPDATE (nor the WHERE) is not necessary since the context of the trigger is the record being updated in the table
user
.