Page 1 of 1

conditional triggers in phpmyadmin

Posted: Thu Nov 27, 2008 12:35 pm
by piyushtiwari
Hi I am trying to set conditional row trigger in phpmyadmin as shown below

CREATE TRIGGER temptri After insert on contact
for each Row
when(New.Age>20)
begin
insert into updates(uName,uAge,uAddr) values(New.Name,New.Age,New.Addr);
END;


I had made delimiter changes but i am getting some error like

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'when(New.Age>20)
begin
insert into updates(uName,uAge,uAddr) values(New.Name,N' at line 3


strange thing is if i take condition out trigger is working fine so in short where i should this condition check

Re: conditional triggers in phpmyadmin

Posted: Thu Nov 27, 2008 11:42 pm
by novice4eva
HUMmmm never heard of WHEN in flow control! Anyways use "IF", do a google search or go through manual coz i feel like you will miss the THEN and END IF :twisted:

Re: conditional triggers in phpmyadmin

Posted: Fri Nov 28, 2008 2:32 am
by piyushtiwari
that too is not working

CREATE TRIGGER temptri
After insert on contact
for each Row
if (new.Age> 100) then
begin
insert into updates(uName,uAddr) values(New.Name,New.Addr);
end;
ENDIF;


#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 8

Re: conditional triggers in phpmyadmin

Posted: Fri Nov 28, 2008 5:54 am
by novice4eva

Code: Select all

 
CREATE TRIGGER temptri
After INSERT ON contact
FOR each Row
BEGIN
IF (new.Age> 100) THEN
INSERT INTO updates(uName,uAddr) VALUES(New.Name,New.Addr);
END IF;
END;
 

Re: conditional triggers in phpmyadmin

Posted: Fri Nov 28, 2008 11:31 am
by piyushtiwari
thanks a lot it worked :) :lol: