• GSquared (1/25/2008)


    checksum doesn't guarantee unique results. It'll probably be unique, but it's not guaranteed. More likely to be unique than Rand() is, though.

    Per BOL:

    CHECKSUM satisfies the properties of a hash function: CHECKSUM applied over any two lists of expressions returns the same value if the corresponding elements of the two lists have the same type and are equal when compared using the equals (=) operator. For the purpose of this definition, NULL values of a given type are considered to compare as equal. If one of the values in the expression list changes, the checksum of the list also usually changes. However, there is a small chance that the checksum will not change.

    From the way I read that it, running a checksum against unique values will return unique values. That's what a hash function does, after all: it returns a unique value that can be used to determine equality. If the hash codes are equal, then so are the values. NEWID() does in fact guarantee uniqueness, so I'm relying on that.

    From testing, I've generated sets of 6 million unique numbers using that and have yet to run into a conflict.

    Am I misreading that somehow? I am making some assumptions, but I thought they were pretty solid.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?