How to reset auto increment column of a table in MySQL

风格不统一 提交于 2020-01-24 18:09:05

问题


I have a table and it's first column sl is auto incrementing. After populating my table, I removed first two rows, and the first entry is having sl 1. Is it possible to reset it to 1 maintaining AI? I am using PHP MyAdmin.


回答1:


I'm not sure if i got your question but if you want your column sl to be renumbered do ALTER TABLE your_table DROP sl and then ALTER TABLE your_table ADD sl your_definitions




回答2:


ALTER TABLE tablename AUTO_INCREMENT = 1;



回答3:


If you just want to reset the auto-number back to 1 you can use either:

DBCC CHECKIDENT (tablename, RESEED, 0)

or

TRUNCATE TABLE tablename

The first option will simply reset your auto-number counter while the second will clear your table of all data and reset the counter.

Is this what you were asking?




回答4:


Try using ALTER TABLE tableName AUTO_INCREMENT=0;. The next record will be entered with index 1.



来源:https://stackoverflow.com/questions/10753511/how-to-reset-auto-increment-column-of-a-table-in-mysql

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