1 year ago
#70642
wingyip
Allocate unique codes to records
We are being given a range of numbers which need to be used on some of our orders.
We must ensure that each number is allocated only once. The range of numbers may be more than a million items (not sure at this stage how many digits but assuming less than 10). I was thinking of prepopulating a table with these numbers so that every time one is used we can update that row with perhaps the orderid.
Table would be:
Id int, Code int, OrderId uniqueidentifier, Date datetime
When getting the latest number for allocating to an order we would find the min(Code) where OrderId is null
Id would be Primary Key but Clustered index will be set on Code column as that will be used for most important query.
Does this sound like a good way to go about doing this? Is there a better way?
sql-server
azure-sql-database
azure-sql-server
0 Answers
Your Answer