I want to make the code that if any of new column’s value is null
change that one to the value of row before with trigger event
CREATE TRIGGER updateField BEFORE INSERT ON message
FOR EACH ROW
IF (NEW.COLUMN IS NULL) then
set NEW.COLUMN = SELECT THE_COLUMN FROM Table ORDER BY ID DESC LIMIT 1;
END IF
2
Answers
If you use a compound statement like
IF/THEN/END IF
, you must put the body of the trigger in aBEGIN..END
block.You must also have a
BEGIN
andEND
if you have more than a code line