MySQL Forums
Forum List  »  Triggers

Re: Synchronizing data between different databases/tables
Posted by: Peter Brawley
Date: October 21, 2010 03:51PM

Your triggers form an endless loop. MySQL Triggers will not allow that or any other form of recursion.

You'll need to interrupt recursion by tracking where inserts, updates & deletes are originating, eg ...

drop table if exists a,b;
create table a(i int,here bool);
create table b like a;

delimiter go
create trigger ains after insert on a for each row
begin
  if new.here=1 then
    insert into b values(new.i,0);
  end if;
end;
go

create trigger bins after insert on b for each row
begin
  if new.here=1 then
    insert into a values(new.i,0);
  end if;
end;
go

delimiter ;

insert into a values(1,1);
insert into b values(2,1);
select * from a;
+------+------+
| i    | here |
+------+------+
|    1 |    1 |
|    2 |    0 |
+------+------+
select * from b;
+------+------+
| i    | here |
+------+------+
|    1 |    1 |
|    2 |    0 |
+------+------+

Options: ReplyQuote


Subject
Views
Written By
Posted
1751
October 21, 2010 01:01PM
Re: Synchronizing data between different databases/tables
2596
October 21, 2010 03:51PM


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.