tags:

views:

84

answers:

4

Will the ID auto-increment value be reset if I drop (wipe) a MySQL table? And, if I delete (for example) the entry N° 535, will this entry number be filled again later?

I don't want that ID to be filled with other new entries if I wiped old data. If this is not the behavior, then what's the solution to avoid this?

+3  A: 

Which DBMS are you using? MySQL does reset the auto-increment value when you TRUNCATE a table. You can use the (much slower) DELETE FROM tablename to avoid this.

Wim
Thanks, got it, i have mySQL
David
A: 

Yes. The solution would be to not DROP your table. Instead use DELETE FROM ...

hobodave
A: 

If you drop a table, it will be gone along with any identity seed values.

cdonner
+1  A: 

The auto_increment value doesn't change if you DELETE a line, but it is reseted if you do a TRUNCATE TABLE. And the next ID is always the current auto_increment value ("gaps" aren't filled again). You can change the auto_increment value with ALTER TABLE table AUTO_INCREMENT = num

Pikrass