Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

Generate Custom Three Digit ID in MySQL with Repeating Sequence

$
0
0

I have a problem generating var char ID in MySQL with repeating Sequence

Need Following Format....

ID                    Client ID          Department

001-01               001                    HR

001-02               001                    AV

002-01               002                    HR

002-02               002                    HR

003-01               003                  Accounts

i have use trigger to achieve generate  three digit id but problem for repeating sequence

INSERT INTO sequencetable VALUES (NULL);
  SET NEW.ID = CONCAT(LPAD(new.clientID,'-',LAST_INSERT_ID(), 2, '0'));

this trigger work fine. and generate ID look like this

ID                    Client ID          Department

001-01               001                    HR

001-02               001                    AV

002-03               002                    HR

002-04               002                    HR

003-05               003                  Accounts

but we don't need this format we need previous Format because sequence is not Repeated


Viewing all articles
Browse latest Browse all 1350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>