The Basics of Using a Sequence as a Table Default

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 719726

  • DaveBoltman

    SSC Enthusiast

    Points: 182

    Aha! Great article, and I can immediately see a use case for having unique numbers even across different tables, where both tables get the number generated by the same sequence. e.g:

    INSERT Table1 -- generates 1
    INSERT Table1 -- generates 2

    INSERT Table2 -- generates 3

    INSERT Table1 -- generates 4
    INSERT Table1 -- generates 5

    INSERT Table2 -- generates 6
    INSERT Table2 -- generates 7
    INSERT Table2 -- generates 8
  • Jeff Moden

    SSC Guru

    Points: 996622

    DaveBoltman wrote:

    Aha! Great article, and I can immediately see a use case for having unique numbers even across different tables, where both tables get the number generated by the same sequence. e.g:

    INSERT Table1 -- generates 1
    INSERT Table1 -- generates 2

    INSERT Table2 -- generates 3

    INSERT Table1 -- generates 4
    INSERT Table1 -- generates 5

    INSERT Table2 -- generates 6
    INSERT Table2 -- generates 7
    INSERT Table2 -- generates 8

    That a good demonstration but why would you need to do such a thing that wouldn't be a violation of good design?  Not trying to start a fight here.  I just can't think of a good reason to do such a thing.

     

    --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".
    "If "pre-optimization" is the root of all evil, then what does the resulting no optimization lead to?"

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

  • Jeff Moden

    SSC Guru

    Points: 996622

    Steve, great article.  Thanks for taking the time to write it up, work out the nice simple demo's and post it all.  Well done!

    --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".
    "If "pre-optimization" is the root of all evil, then what does the resulting no optimization lead to?"

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

  • shamsmehra90

    Newbie

    Points: 1

    i also want some details

  • Jeff Moden

    SSC Guru

    Points: 996622

    shamsmehra90 wrote:

    i also want some details

    Details on what?  Don't expect folks to read every post on this thread to figure out what you're talking about.  Be specific or quote the post you're identifying with!  😉

    --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".
    "If "pre-optimization" is the root of all evil, then what does the resulting no optimization lead to?"

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

Viewing 6 posts - 1 through 6 (of 6 total)

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