Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a unique order number

Algorithmically speaking, how could I generate a unique, human readable, reasonably lengthed - order number for SQL Server column. The only requirement is that it references the Customer Number and can be easily repeated over the phone.

Something like:

  • Customer Number - XXXXXXXX - XXXXXXXX

RT65-XXXXXXXX-XXXXXXXX

How would I generate the XXXXXXXX? (Use random alpha-numeric data and then checking to see if it was in fact a duplicate?)

and

What are the best methods/considerations when generating these types of numbers?

How have you done this in your application?


2 Answers

Use an identity column and pad with zeros.

Alter the start and increment values to taste.

Optionally, add a CRC check digit.

like image 68
wefwfwefwe Avatar answered Oct 31 '25 13:10

wefwfwefwe


Check out these posts, nearly the exact same question. Real good data in both (I've used them before):

A good algorithm for generating an order number

What is the best format for a customer number, order number?

like image 27
dpb Avatar answered Oct 31 '25 12:10

dpb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!