Sequences I

  • Thanks, learned something new.

    ----------------------------------------------------------------------------
    Sacramento SQL Server users group - http://sac.sqlpass.org
    Follow me on Twitter - @SQLDCH
    ----------------------------------------------------------------------------

    Yeah, well...The Dude abides.
  • jfogel (4/17/2012)


    Got it right. It is nice to see the sequence feature is now in SQL Server. Mainly because developers had to use a sequence for Oracle and an identity column for SQL Server. At least now the code can move closer to being the same. Note I wrote closer.

    Yes, I agree. After all these years it is good to see it being implemented in SQL Server.

  • tks for the questions - +1 for learned something new today. cheers

  • Good one. Good to know since I still don't have access to SQL Server 2012, but eventually will.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

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

  • Thanks for the 2012 question. Keep 'em coming.

  • deleted due to embarrisment.

    Adam Zacks-------------------------------------------Be Nice, Or Leave

  • Schadenfreude-Mei (4/17/2012)


    Sorry guys but I took a guess, got it wrong so ran it through my local 2k8r2 and get the below:

    Msg 343, Level 15, State 1, Line 1

    Unknown object type 'SEQUENCE' used in a CREATE, DROP, or ALTER statement.

    Msg 102, Level 15, State 1, Line 3

    Incorrect syntax near ';'.

    Msg 343, Level 15, State 1, Line 5

    Unknown object type 'SEQUENCE' used in CREATE, DROP, or ALTER statement.

    SO what gives?

    This feature requires SQL 2012.

  • Yes, note the wording of the question.

  • Schadenfreude-Mei (4/17/2012)


    Sorry guys but I took a guess, got it wrong so ran it through my local 2k8r2 and get the below:

    Msg 343, Level 15, State 1, Line 1

    Unknown object type 'SEQUENCE' used in a CREATE, DROP, or ALTER statement.

    Msg 102, Level 15, State 1, Line 3

    Incorrect syntax near ';'.

    Msg 343, Level 15, State 1, Line 5

    Unknown object type 'SEQUENCE' used in CREATE, DROP, or ALTER statement.

    SO what gives?

    From the question:

    In a default installation of SQL Server 2012...

    From the answer:

    Sequences, a new feature in SQL Server 2012,...

  • Schadenfreude-Mei (4/17/2012)


    deleted due to embarrisment.

    Thanks, made me laugh. 🙂

  • Schadenfreude-Mei (4/17/2012)


    deleted due to embarrisment.

    We did kind of jump on you, didn't we? Rest assured it wasn't intended (I know when I wrote my post, the other two weren't there). We've all misread questions from time to time, and every once in a while, there actually is a poorly written question.

    😉

  • Nice question

    Thanks

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • for more info ..

    -- #1 long numbers (Carlo doesn't like for Excel)

    CREATE SEQUENCE SSC_ROCKS;

    SELECT N0 = (NEXT VALUE FOR SSC_ROCKS); -- -9223372036854775808

    SELECT N1 = (NEXT VALUE FOR SSC_ROCKS); -- -9223372036854775807

    DROP SEQUENCE SSC_ROCKS;

    GO

    -- #2 try hex string instead

    CREATE SEQUENCE SSC_ROCKX;

    SELECT N0 = [sys].[fn_varbintohexstr](NEXT VALUE FOR SSC_ROCKX); -- 0x8000000000000000

    SELECT N1 = [sys].[fn_varbintohexstr](NEXT VALUE FOR SSC_ROCKX); -- 0x8000000000000001

    DROP SEQUENCE SSC_ROCKX;

    GO

    -- #3 show that ROLLBACK doesn't erase/reset sequence, ie behaves like IDENTITY()

    CREATE SEQUENCE SSC_ROCKT;

    begin tran

    SELECT N0 = [sys].[fn_varbintohexstr](NEXT VALUE FOR SSC_ROCKT); -- 0x8000000000000000

    SELECT N1 = [sys].[fn_varbintohexstr](NEXT VALUE FOR SSC_ROCKT); -- 0x8000000000000001

    rollback

    SELECT N2 = [sys].[fn_varbintohexstr](NEXT VALUE FOR SSC_ROCKT); -- 0x8000000000000002

    DROP SEQUENCE SSC_ROCKT;

    GO

  • Koen Verbeeck (4/17/2012)


    Carlo Romagnano (4/17/2012)


    I am curious to know how many developpers will use default value for "START WITH". In most cases will be a negative number.

    They will all be negative, except for tinyint.

    Only if they don't specify a negative increment (if they do, they will be positive).

    Tom

  • Henrico Bekker (4/16/2012)


    got it wrong, as the correct answer wasn't listed.

    your syntax is wrong in, sequence wouldn't be created to start of with...no increment value, no 'AS'..etc.

    The CREATE SEQUENCE page in Bol gives an example in which the sequence is created by

    CREATE SEQUENCE Test.TestSequence ;

    so clearly MS thinks that not specifying any of those things works.

    Tom

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

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