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
Post a Comment