mySQL Database: Reset AutoIncrement Fields

▼魔方 西西 提交于 2019-12-07 15:54:03

问题


while the development of websites we use the database to test & all... which consumes a lot from auto generated (auto increment) attributes series... how to reset everything...


回答1:


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




回答2:


ALTER TABLE _TABLE_ AUTO_INCREMENT=1




回答3:


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



来源:https://stackoverflow.com/questions/4246959/mysql-database-reset-autoincrement-fields

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