MySQL Forums
Forum List  »  Triggers

Re: trigger with condition
Posted by: Martin Tomczyk
Date: November 30, 2013 04:03PM

HI Peter,

ok. I changed some stuff and hopefully done it right :)
The JOIN and my whole concept were wrong I think. I would have needed a full outer join anyway (If I'm right :))
But I started to go the direction you leaded me to with NEW extension of TRIGGER.
So the new code doing it's job the way I want to.
Maybe you could give some comments. I would really appreciate it.
To summarize the task:
#####################DB-SOURCE#####################|		|################DB-DESTINATION###################
#source table (structure identical to destination)#|		|####table (structure identical to source)########
#_______id______|_______introtext_________________#|		|#______id______|___introtext____________________#
#	1	|	varchar of id1 in source  #|---|	|#	1	|   varchar of id1 in destination#
#	2	|	varchar of id2 in source  #|   |------->|#	2	|   varchar of id2 in destination#
#	3	|	varchar of id3 in source  #|		|#	3	|   varchar of id3 in destination#
The only thing that should happen when the trigger fires is that
only the introtext of id=1 in source table
should be copied to
the introtext of id=2 in destination table
And that only if introtext of id=1 in source table is changed.
In any other cases nothing happens. So the code is:
 
	BEGIN
	IF NEW.id = 1 THEN
	UPDATE db_destination.table_content custom_destination
	SET custom_destination.introtext = NEW.introtext
	WHERE custom_destination.id = 2;
	END IF;
	END

Thanks a lot.
Martin



Edited 1 time(s). Last edit at 11/30/2013 04:16PM by Martin Tomczyk.

Options: ReplyQuote


Subject
Views
Written By
Posted
2735
November 29, 2013 07:01AM
1388
November 29, 2013 12:27PM
1439
November 29, 2013 02:21PM
Re: trigger with condition
1332
November 30, 2013 04:03PM
1360
November 30, 2013 11:37PM
1291
December 01, 2013 03:52AM
1287
December 01, 2013 01:46PM
1309
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.