0

I hoped something as below will be successful. But SQL syntax error... Clearly i don't want to insert data into a table if only a special data is changed.

CREATE TRIGGER `before_access_update` BEFORE UPDATE ON `access` FOR EACH ROW IF NOT (NEW.pin<>OLD.pin) THEN
INSERT INTO access_audit
SET action = 'update',
    a_lastname = OLD.lastname,
    a_firstname = OLD.firstname,
    changed_on = NOW();
END IF;

1 Answer 1

1

You use a ; in your trigger, therefore you have to use another query delimiter for the trigger itself:

DELIMITER $$
CREATE TRIGGER `before_access_update` BEFORE UPDATE ON `access` FOR EACH ROW IF NOT (NEW.pin<>OLD.pin) THEN
INSERT INTO access_audit
SET action = 'update',
    a_lastname = OLD.lastname,
    a_firstname = OLD.firstname,
    changed_on = NOW();
END IF$$
DELIMITER ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.