Generate a sequence in mysql -
i want enter value/sequence mysql field automatically. here sequence:
2342/abc/2013/08/01
the last 1 sequence 01
, 02
, 03
, , on.
the rule when month changes in above month 08 when 09
want start sequence again 01
, 02
, on.
i have table table1(id,user_name,sq_number)
i use this
insert table1('user_name') values('bill')
it insert sequence automatically
use before insert trigger, (below create sequence current date), add logic (it's not clear me).
create trigger insert_processor before insert on table1 each row begin set new.sq_number = concat('2342','/','abc','/', date_format(now(),'%y/%m/%d')); end$$
if need unique sequence it's practice create table , use select in trigger.
Comments
Post a Comment