0

I would like to fire an UPDATE trigger only if a certain fields has been modified. Is it possible to do with a if statement; execute a particular query.

Exemple (Not working as shown):

DROP TRIGGER IF EXISTS `catch_mytable_update`//
CREATE TRIGGER `catch_mytable_update` AFTER UPDATE ON `mytable`
 FOR EACH ROW BEGIN

IF (old.name != new.name) THEN

DELETE FROM trigger WHERE tablename='mytable' AND rowid = new.id;
INSERT INTO trigger (tablename, rowid, cmd, cmduser, time) VALUES('mytable', new.id, 'UPDATE', CURRENT_USER(), NOW());

ENDIF//

END//

Delimiter: //

1 Answer 1

1

Try changing:

    IF (name.old != name.new) THEN

to:

    IF old.name != new.name THEN
Sign up to request clarification or add additional context in comments.

8 Comments

Sorry, yes are right. This was a spelling mistake when I typed the question. I tried the change, and I am still getting an error :(
We'll need to know the MySQL error code or message for us to help :)
Here is the following error I get when I run the query mentioned: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 9
Also, what is the table that's named 'trigger' actually used for?
The table trigger is used for monitoring triggers occurring in several tables. This query already works fine with no IF statement. thx
|

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.