MySQL Forums
Forum List  »  Triggers

trigger with condition
Posted by: Martin Tomczyk
Date: November 29, 2013 07:01AM

Hi,

I'm not an expert in this and have a task to solve that for me seems not that easy.
I'm having two databases with tables. structure is identical.
Now I want to copy (with an UPDATE) only one field of one row (specific source id will stay the same) to th eother row in the destination table (also here one fixed id which wil stay the same) if it has been changed.
So I setup the trigger on the source db and coded this:
create TRIGGER ‘sync’ AFTER UPDATE ON sourcetable
FOR EACH ROW
BEGIN
UPDATE db_destination.table_content custom_destination
INNER JOIN db_source.table_content custom_source
SET custom_destination.introtext = custom_source.introtext 
WHERE custom_destination.id = 2 AND custom_source.id = 1;
END
It is working fine...but it updates always by the meaning of it updates even if I have not edited the one source from row with id = 1. If I edit for example on id = 15 in source table the UPDATE statemnt gets triggered and updates destination with id = 2 from source with id = 1.
How can I avoid this that it only triggers when source id =1 has been changed?

Thanks a lot for any support.
Martin



Edited 1 time(s). Last edit at 11/29/2013 08:12AM by Martin Tomczyk.

Options: ReplyQuote


Subject
Views
Written By
Posted
trigger with condition
2345
November 29, 2013 07:01AM
1187
November 29, 2013 12:27PM
1155
November 29, 2013 02:21PM
1124
November 30, 2013 04:03PM
1195
November 30, 2013 11:37PM
1059
December 01, 2013 03:52AM
1044
December 01, 2013 01:46PM
1088
December 01, 2013 03:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.