Generate consecutive numbers

  • Comments posted to this topic are about the item Generate consecutive numbers

  • In my case (not being an administrator, or maybe it's just our new SQL 2005 database) the master.sys.columns only has 44 rows, and the query only supplies 85,184 rows (44 cubed).

    If it had only 3 more rows it would have reached the 100,000 mark.

    But using the INFORMATION_SCHEMA.COLUMNS view with 4140 rows worked fine, and would give up to 70,000,000,000 consecutive numbers.

  • Oh, be careful, now...

    That's why I use sys.all_columns. Even on a brand new instance, it contains more than 4,000 rows when all features are installed correctly and it doesn't matter which database is the current database so long as you have the necessary privs.

    INFORMATION_SCHEMA.COLUMNS, on the other hand, can have zero rows in it on a new database and certainly a whole lot less than 4,000 rows.

    --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)

  • This is actually pretty cool. It's a great lesson on the use of ROW_NUMBER and OVER which I rarely get a chance to use.

Viewing 4 posts - 1 through 3 (of 3 total)

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