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