MYSQL Stored procedure for concatenating code -
i have table contain fields(id,code,name,...), when want insert new record code field should (abc-001) , next record should (abc-002) , on. want write mysql procedure don't know how, body has idea? in advance
first user insert query like:
insert yourtable values(..,'abc',...);
now write trigger after update set code value in expected format:
create trigger triggernmae after insert on yourtable each row begin update yourtable set code = concat(code,'-',lpad(new.id,3,'0')); id = new.id ; end;
mysql
No comments:
Post a Comment