I need to generate a 9 digit order id without any leading zeroes. What is the best way to do this ?
What I think of is: Create a Table with a unique ID Column and then generate a random number between 100000000 and 999999999 in C# Code and try to insert it into the table until I am successful. What are the chances of getting Unique Constraint Exception in this and re-generating the number ?
If I am thinking in the right direction, is there any way to do this in the sql server itself rather than handling exception in the C# code and then re-generating ?
Or is there any other best method to do this ?
Thanks
Well. It would probably even work if number of your transactions would remain relatively low compared to all the possibilities, but that seems really wrong. Catching exceptions and retrying?
Do you have any reasons not to use autoincrement key, starting with 100000000 and counting?