mySQL Database: Reset AutoIncrement Fields

倾然丶 夕夏残阳落幕 提交于 2019-12-06 03:01:57

Assuming you're deleting the records when you're done testing, a TRUNCATE command will delete all records and reset the autoincrement value.

ALTER TABLE _TABLE_ AUTO_INCREMENT=1

Another possibility, avoiding transactions and resetting the autoincrement counter could be to combine the select to get the next available id and the insert itself;

INSERT INTO tablename (id, somefield1, somefield2) SELECT max(id)+1, 'test', 5 FROM tablename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!