vhage dela cruz
vhage dela cruz

Reputation: 21

MySQL Trigger Update other Table

Please someone help me.

I`m trying to create a Trigger that when table1 is Updated table2 will also be updated.

Please Check.

CREATE TRIGGER up_trig
AFTER UPDATE ON table1
FOR EACH ROW
begin
update table2
set name2 = name1
where name2 <> name1
and id2 = id1;

end

I really need this one please help me.

Upvotes: 1

Views: 153

Answers (1)

juergen d
juergen d

Reputation: 204766

Don't forget the delimiter and the ; after the end:

delimiter |

CREATE TRIGGER up_trig
AFTER UPDATE ON table1
FOR EACH ROW
begin
   update table2
   set name2 = NEW.name1
   where name2 <> NEW.name1
   and id2 = NEW.id1;
end;

|

Upvotes: 2

Related Questions