Page 1 of 4 123 ... LastLast
Results 1 to 15 of 46
  1. #1
    Join Date
    Jan 2008
    Posts
    186

    Unanswered: Auto-increment: Start at 1 or 0?

    Is there any ANSI standard to whether or not auto increment values should start at 1 or 0?

    What do you guys typically do?

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    1

    0 is the absence of value. hence, if you have a record, ohhhh nevermind.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Jan 2008
    Posts
    186
    Ahhh okay, that makes sense. So aside from sql server, do you know if most of the the other popular DBMS start their auto increments at 1 then?

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Thrasymachus
    0 is the absence of value
    bzzzzzt, wrong

    NULL is the absence of value

    thanks for playing, please try again

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by dbguyfh
    Is there any ANSI standard to whether or not auto increment values should start at 1 or 0?
    no, the ANSI standard doesn't even recognize auto increments -- these are abominations invented by the DBMS vendors

    what i typically do is start my IDENTITY values at 937937937 and set the increment value at -12345

    this has the added advantage that the most recent rows are displayed first

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Its a surrogate key. It has no relevance to the data whatsoever. Therefore, it makes no difference what number you start at.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  7. #7
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Quote Originally Posted by r937
    bzzzzzt, wrong

    NULL is the absence of value

    thanks for playing, please try again


    bbbzzzzzzzzttttt. I appeal to wikipedia....

    "zero may also be called null or nil"

    http://en.wikipedia.org/wiki/0_(number)
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  8. #8
    Join Date
    Jan 2008
    Posts
    186
    Okay, so it looks like you can do it either way, and there is no standard.

    But what do most DBMS default to?

    Seems like 1 from my search attempts.

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Thrasymachus
    bbbzzzzzzzzttttt. I appeal to wikipedia....

    "zero may also be called null or nil"

    http://en.wikipedia.org/wiki/0_(number)
    $deity help you if you rely on wikipedia as your technical authority

    besides, you're misinterpreting a general term (null or nil) with a very specific database term

    you're gonna love oracle... oracle treats empty strings as NULLs
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  10. #10
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    it's on the internet, so it must be true.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  11. #11
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    What the hell is ZERO if it is not the absence of value or null.

    Show me 0 dollars in my hand.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  12. #12
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    hand? there is no hand
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  13. #13
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    go ahead and be coy with your absence of a response. I am heading to happy hour with the new co-workers.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  14. #14
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Zero does have a value, it's equidistant between 1 and -1.
    NULL however is an unknown value, i.e. x

    Next lesson we'll learn more about infinity and move on to imaginary numbers
    George
    Home | Blog

  15. #15
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Zero is a value. Null is not a value. Wikipedia is wrong.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •