1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Why Primary ID is not starts from zero?

Discussion in 'MySQL' started by Litonice09, Apr 19, 2013.

  1. #1
    When a column like ID is a primary key and auto increment defined. It starts from 1. Why it is not starts from zero? Anybody can give me proper answer with examples.... Thanks in advance.
     
    Litonice09, Apr 19, 2013 IP
  2. diplox

    diplox Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    By default passing a value of zero as the id for an auto-increment field is the same as passing NULL. So I think the reason why IDs start at 1 is just to avoid confusion when passing a zero value, since zero is functionally equivalent to passing NULL in that it causes the database to automatically generate a new ID.

    You can change the starting auto-increment value using alter table, example:
    
    ALTER TABLE table auto_increment = 100; 
    
    Code (markup):
    Which should start IDs at 100. You can't set them to zero AFAIK, setting it to zero will force the default starting ID of 1.
     
    diplox, Apr 19, 2013 IP