How to create a MySQL trigger that fires on UPDATE when a specific field changes

Practice




in Oracle there are similar constructs, but can this also be done in mysql?

How to make a mysql update trigger fire only when a specific field changes, not the whole row

CREATE TRIGGER tab.event
BEFORE
INSERT OR UPDATE OF id, tex ON tab.emp
FOR EACH ROW

CREATE
DEFINER = 'root'@'127.0.0.1'
TRIGGER baza.logevent
AFTER UPDATE
ON baza.user
FOR EACH ROW
BEGIN

IF (@DISABLE_TRIGGERS IS NULL) and (OLD.status <> NEW.status) THEN

INSERT INTO feed Set feed.id_event = NEW.id , feed.userId = NEW.Id;
INSERT INTO changestatus Set changestatus.id_user = NEW.id , changestatus.text_status = OLD.status;

END IF;




END





as an option, you can check whether the field has changed or not (OLD.status <> NEW.status)

Also, don't forget what values can occur for which event type (INSERT UPDATE DELETE before-after)

How to create a MySQL trigger that fires on UPDATE when a specific field changes

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)