conditional triggers in phpmyadmin

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
piyushtiwari
Forum Newbie
Posts: 5
Joined: Mon Nov 24, 2008 8:41 am

conditional triggers in phpmyadmin

Post 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
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: conditional triggers in phpmyadmin

Post 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:
piyushtiwari
Forum Newbie
Posts: 5
Joined: Mon Nov 24, 2008 8:41 am

Re: conditional triggers in phpmyadmin

Post 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
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: conditional triggers in phpmyadmin

Post 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;
 
piyushtiwari
Forum Newbie
Posts: 5
Joined: Mon Nov 24, 2008 8:41 am

Re: conditional triggers in phpmyadmin

Post by piyushtiwari »

thanks a lot it worked :) :lol:
Post Reply