Web Analytics Made Easy -
StatCounter Strange auto-increment behavior - CodingForum


No announcement yet.

Strange auto-increment behavior

  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange auto-increment behavior

    I'm trying to figure out why the following happens, which seems to be very strange behavior:

    If I insert data to a table which has an auto-incrementing id-column, the id does not increase as I expect it woud. In a table with 4 values (numbered 0 to 3), for example, a new row inserted began it's ID at 43, then continued to 44, 45, etc.

    Another related issue is that if I restructure a table that has data present in it, the row with an id of 0 (on an auto-increment column) jumps around to a seemingly random high number, again, like 43.

    Thanks if anybody has any info on this. I'm baffled.

  • #2
    it may be that the table has been used before and had all records deleted, but still holds the auto increment value. Also, some tables can be set up to start at a certain auto-increment value. This option is usually selected when exporting a table.

    Providing you have no data in the table that you need, try:

    TRUNCATE `table_name`
    PHP Weekly - A PHP Developers Resource
    PHP 5.1.4 and Ruby on Rails web hosting
    Moderator of PHP and Work offers and Requests
    Install Apache/PHP/MySQL
    (by marek_mar) | TinyPlugin Architecture