• I've really got to respectfully disagree... the use of a "sequence" table of any kind will become a major hotspot, a possible source of a huge number of deadlocks, and will generally prevent any and all code from being set-based without the presence of temporary working tables and a bunch of computational hooie to get the ID's out of the sequence table. Having two columns in the same table is also and absolutely the wrong way to do this.

    The correct way to do this, if it must be done, is to use a "Partitioned" table. No if's, ands, or but's, it's the only way to go with something like this.

    Just say "NO" to sequence tables... they are a form of "Death by SQL". We had one in our old company and, until I made everyone toe-the-line and wrote a nasty code change, it was the single source of an average of 640 deadlocks per day with spikes up to 4000 deadlocks in a single day.

    If you never trust me on anything else, trust me on this! 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)