List:General Discussion« Previous MessageNext Message »
From:Peter Brawley Date:July 10 2011 11:21am
Subject:Re: Mysql Trigger
View as plain text  
On 7/10/2011 3:32 AM, vishesh kumar wrote:Hi Members
> Whats wrong i am doing in following create trigger statement
>
>    Create trigger test before insert on user
>     for each row
>     begin
>        set New.host=upper(new.host)
>     end
>
> Above statement giving error check sql syntax , please  guide me. I want to
> put host field value in uppercase in user table
One-liners don't need DELIMITERs, so you can write:

create trigger test before insert on user for each row set new.host=upper(new.host);

Multi-line Triggers need BEGIN...END so they need DELIMITERs too:

drop trigger if exists test;
delimiter go
create trigger test before insert on user for each row
begin
   set new.c=upper(new.c);
   set ...&c ...
end;
go
delimiter ;

A note on names: once you have too many tables & Triggers to remember, 
you wish you'd adopted a naming convention that helps you remember 
object names. A good convention for Trigger names is 
TablenameWhenAction, so yours would be TestBeforeIns.
PB

Thread
Mysql Triggervishesh kumar10 Jul
  • Re: Mysql TriggerReindl Harald10 Jul
    • Re: Mysql Triggervishesh kumar10 Jul
  • Re: Mysql TriggerPeter Brawley10 Jul