10 digit random unique alpha-numeric number

  • Abhijeet Dighe (1/14/2010)


    Thanks.

    But if I take only 10 characters of string generated using newid() like this:

    select CONVERT(varchar(10), right(newid(),10))

    still will it generate unique string?

    It depends upon the scope of your requirement. If you want to use it for uniquely identifying gender in a lookup table, with say 4 values (female, male, unknown, answer declined) then the answer is almost certainly going to be Yes. If you are hoping to use it to uniquely identify every person on the planet, then the answer is likely to be No. The key word is "Likely" - how likely is it that a 10-character near-random string will reappear in 4 iterations? How about 4 billion iterations?

    What do you want to use this for? There may be better alternatives:

    "How can I swim across the river without getting my hair wet?"

    "Don't swim - use the bridge"

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • I want it for storing transaction no.

    I think it will be better to check in database for uniqueness.

  • Abhijeet Dighe (1/14/2010)


    I want it for storing transaction no.

    I think it will be better to check in database for uniqueness.

    Transaction no.? As in named transactions?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Abhijeet Dighe (1/14/2010)


    I want it for storing transaction no.

    I think it will be better to check in database for uniqueness.

    any reason for not using an identity ?



    Clear Sky SQL
    My Blog[/url]

  • I am working on an old project, which is using 10 digit string for tracking credit card transactions. But problem with the old code is that sometimes it generates duplicate transaction no. I don't want to change old code, this is why I am not using identity.

  • This worked perfectly! Thanks!

Viewing 6 posts - 16 through 20 (of 20 total)

You must be logged in to reply to this topic. Login to reply