Creating a BEFORE INSERT TRIGGER IN MYSQL -


i need creating before insert trigger on mysql bench. im new please.

create table `quincyninying`.`toytracking` ( `toyid` int not null, `toyname` varchar(50) null, `toycost` decimal null, `toyaction` varchar(50) null, `actiondate` datetime null,  primary key (`toyid`));  create table `quincyninying`.`toy` ( `toyid` int not null, `toyname` varchar(50) null, `toycost` decimal null, primary key (`toyid`)); 

create before insert trigger on toy table adds record toytracking table information toy table record being inserted, hard coded toyaction ‘insert’ , current date , time record inserted.

error 1054: unknown column 'inserted' in 'new' sql statement: create definer = current_user trigger `quincyninying`.`toy_before_insert` before insert on `toy`  each row begin     if new.inserted         set @toyaction = 'delete';     else          set @toyaction = 'new';     end if;      insert `quincyninying`.`toytracking` (toyid, toyname, toycost,     toyaction, actiondate)     values       (new.toyid, new.toyname, new.toycost,@toyaction, now());  end 

it throws me error saying " error 1054: unknown column 'inserted' in 'new' "

get rid of if new.inserted test, since there's no column name, , hard-code insert value toyaction column stated in requirements.

create definer = current_user trigger `quincyninying`.`toy_before_insert` before insert on `toy`  each row begin     insert `quincyninying`.`toytracking` (toyid, toyname, toycost, toyaction, actiondate)     values (new.toyid, new.toyname, new.toycost, 'insert', now()); end 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -