0

Quick question regarding phpMyAdmin and autoincrementing. If I add a product and it is assigned id 1, then I delete it before adding another, the next one is given the id 2 even though I deleted id 1. I hope this makes sense.

Does this matter?

RapsFan1981
  • 1,177
  • 3
  • 21
  • 61
  • 1
    Duplicate of http://stackoverflow.com/questions/2214141/mysql-auto-increment-after-delete – Rag Aug 25 '11 at 17:47
  • By the by, you're confusing PHPMyAdmin and MySQL here: you are using PHPMyAdmin (a MySQL client) to access a MySQL Database, just like you are using Firefox to access a website (stackoverflow). This behaviour is not PHPMyAdmin, but is MySQL. – Konerak Aug 25 '11 at 17:57
  • http://stackoverflow.com/questions/449346/mysql-auto-increment-does-not-rollback - more focused on transactional use of auto_incrementing fields; but still a good discussion of how auto_incrementing should be used. – JHarnach Aug 25 '11 at 18:00

3 Answers3

1

No, this is normal (My)SQL behaviour.

Konerak
  • 39,272
  • 12
  • 98
  • 118
1

Its not the way it works. The auto increment value is stored in a variable, and it only adds one to that, instead of checking the largest one and adding one to that. Its the normal behavior, it looks messy but it works fine.

Gabor Magyar
  • 926
  • 2
  • 9
  • 20
0

Consider the example where you had 1000 rows, and deleted the row ID=1. Would you expect the next entry to be given an ID of 1001 ? or 1 ?

This is working as intended, though if you absolutely must, you can manually set the value just as you would any other column in MySQL.

JHarnach
  • 3,944
  • 7
  • 43
  • 48
  • 1
    You can, but [you should not](http://stackoverflow.com/questions/6121228/how-can-i-change-auto-increment-primary-key-values-on-row-deletion)! – Konerak Aug 25 '11 at 17:58
  • Oh I agree, but the option is there for those who dare :) – JHarnach Aug 25 '11 at 18:01