Sequences II

  • Toreador (4/24/2012)


    Thomas Abraham (4/24/2012)


    this feature behaves as you would design it.

    Which is the reason I guessed wrong 😉

    Ah yes, a SQL Server veteran. Burned by experience, conditioned to expect the unexpected.

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • damn it! MISTAKE with the cycle/no cycle argument not related with the start value!

    I didn't know that the start value for the sequence is the maximum for a ascending sequence. Let's learning. :w00t:

  • damn it! MISTAKE with the cycle/no cycle argument not related with the start value!

    I didn't know that the start value for the sequence is the maximum for a ascending sequence. Let's learning. :w00t:

  • OK no longer confused or perplexed -

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Removed as issue is moot now that Ron is back in our space-time continuum.

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Thomas Abraham (4/24/2012)


    bitbucket-25253 (4/24/2012)


    ... 2nd select returns 2147483646 yes the sequence is descending, but still not what is the supposed correct answer, so I am still confused and perplexed.

    Now I'm confused. What do you think is the supposed answer? I answered, and the answered page shows as correct 2147483646.

    My apologies .... YOU ARE CORRECT

    I should have finished my first cup of coffee before even attempting to answer and then wondering why what I selected was incorrect.

    Again My apologies -

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • bitbucket-25253 (4/24/2012)

    My apologies .... YOU ARE CORRECT

    I should have finished my first cup of coffee before even attempting to answer and then wondering why what I selected was incorrect.

    Again My apologies -

    No apology necessary. However, it should demonstrate the esteem your signature carries that, in spite of getting it correct, I was willing to consider that you saw something I didn't.

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Thomas Abraham (4/24/2012)


    I think if you give it some thought, this feature behaves as you would design it. The defaults seem the way I would hope they would - for a pleasant change.

    Exactly. I heard of sequences at Dev Connections last month, and immediately thought of some "gotchas" that might make them somewhat difficult to work with. So I wrote some tests, whence came these questions (there's one more in the sequence by the way ; )

    Every test I tried worked. Essentially, from what I could tell, you have to ignore the defaults or deliberately do something odd to break sequences in SQL 2012.

    So (and I don't say this very often) Bravo, Microsoft!

  • sqlmunkee (4/24/2012)


    So, the key bit here is that SQL will *decide* whether the sequence is ascending or descending based on the INCREMENT BY argument. That's a bit misleading if your just starting out with sequences and SQL 2012 (like me) 🙂 Good question !

    I agree that it seems misleading or confusing. That's why I always code the details even if they are the defaults and not required. That way, there is no question when someone else reads the code. It gets a little wordy but it alleviates confusion.

    It's good to learn the new stuff. 🙂

  • OCTom (4/24/2012)


    sqlmunkee (4/24/2012)


    So, the key bit here is that SQL will *decide* whether the sequence is ascending or descending based on the INCREMENT BY argument. That's a bit misleading if your just starting out with sequences and SQL 2012 (like me) 🙂 Good question !

    I agree that it seems misleading or confusing. That's why I always code the details even if they are the defaults and not required. That way, there is no question when someone else reads the code. It gets a little wordy but it alleviates confusion.

    It's good to learn the new stuff. 🙂

    Good point, always code the details which should remove any ambiguity or confusion.

    Good question.

  • Toreador (4/24/2012)


    Thomas Abraham (4/24/2012)


    this feature behaves as you would design it.

    Which is the reason I guessed wrong 😉

    +1 😀

    Great question. Need to dig into the new 2012 features more.

    Cheers

  • Great question. Looking forward to using this feature in an upcoming project....

    Rob Schripsema
    Propack, Inc.

  • Good one

    ...[-2147483648,-2147483647, ... ,2147483646,2147483647],[-2147483648,-2147483647, ... ,2147483646,2147483647]...

    IgorMi

    Igor Micev,My blog: www.igormicev.com

  • Excellent question. I had to read and re-read BOL to get it right. Seems that sequences with default values are tricky to understand, but I found that reading the specific points make sense to their behavior.

    From BOL (http://msdn.microsoft.com/en-us/library/ff878091.aspx):

    START WITH <constant>

    The first value returned by the sequence object. The START value must be a value less than or equal to the maximum and greater than or equal to the minimum value of the sequence object. The default start value for a new sequence object is the minimum value for an ascending sequence object and the maximum value for a descending sequence object.

    INCREMENT BY <constant>

    Value used to increment (or decrement if negative) the value of the sequence object for each call to the NEXT VALUE FOR function. If the increment is a negative value, the sequence object is descending; otherwise, it is ascending. The increment cannot be 0. The default increment for a new sequence object is 1.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • Thanks for an easy one!

Viewing 15 posts - 16 through 30 (of 40 total)

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