开发者

Does dropping a SQL table reset its ID value?

Will the ID auto-increment value be reset if I drop (wipe) a MySQL table? An开发者_Go百科d, 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?


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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜