Tab_1
"id" "name" "addr" "country" "status"
"1" "norman" "1st" "US" "2"
"2" "kirk" "2nd" "US" "2"
Tab_2
"id" "name" "addr" "country" "pos" "total"
"1" "norman" "1st" "US" "0" "0"
"2" "kirk" "2nd" "US" "0" "0"
I'm using the below trigger after update
on Tab_1
to update
Tab_2
when the status in Tab_1
is set to 0
. Problem is, It'll do nothing even when It's correct. How do I set this right?
CREATE DEFINER=`root`@`localhost` TRIGGER `tab_2_upd` AFTER UPDATE ON `tab_1`
FOR EACH ROW BEGIN
if new.status = '0' then
update tab_2 set pos = pos+1, total = total+1 where id = new.id;
//Should it be new.id or old.id? I tried both but still no luck.
end if;
END