A good algorithm for generating an order number

前端 未结 10 1470
青春惊慌失措
青春惊慌失措 2021-01-31 06:27

As much as I like using GUIDs as the unique identifiers in my system, it is not very user-friendly for fields like an order number where a customer may have to repeat that to a

10条回答
  •  感情败类
    2021-01-31 07:08

    OK sounds like a classic case of premature optimisation. You imagine a performance problem (Oh my god I have to access the - horror - database to get an order number! My that might be slow) and end up with a convoluted mess of psuedo random generators and a ton of duplicate handling code.

    One simple practical answer is to run a sequence per customer. The real order number being a composite of customer number and order number. You can easily retrieve the last sequence used when retriving other stuff about your customer.

提交回复
热议问题