mysql - Trigger insert on the same table -


i have table :

table t1 ( id int autoincremente, numero varchar ) 

i need set value of numero = prefix + id when there insert.

so tryed using trigger :

create trigger `mysweettrigger` after insert on `t1` each row begin     set new.numero = concat('prefix', new.id); end 

but can't make work...

thanks in advance help.

the after insert trigger not allowed modify it's own data. before insert not have auto increment value available. looks problem.

luckily can access auto increment value schema.

create trigger `mysweettrigger` before insert on `t1` each row begin     set new.numero = concat('prefix',        (         select            auto_increment          information_schema.tables          table_schema=database() , table_name='t1'       )); end 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -