如何重置 MySql 表中的自动增量编号/列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10697196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reset the auto increment number/column in a MySql table
提问by Parthi04
The item_category_id column is auto increment value in the mysql table.
item_category_id 列是 mysql 表中的自动增量值。
I need to delete all the values & next insertion should start from 1. If i delete all values & try to insert a new row then it starts with some 30's & 40's.
我需要删除所有值 & 下一次插入应该从 1 开始。如果我删除所有值 & 尝试插入一个新行,那么它从 30 年代和 40 年代开始。
item_category_id item_category_name
1 qqq
25 ccc
32 vvv
29 bb
4 bbb
31 hhh
34 mmm
33 rrr
回答by mprabhat
ALTER TABLE TABLENAME AUTO_INCREMENT = 1
Instead of using Delete if you use Truncate that will remove data and will also reset autoincrement.
如果使用 Truncate 将删除数据并重置自动增量,而不是使用 Delete。
TRUNCATE TABLE TABLENAME
回答by ServAce85
If you're using PHPmyAdmin to manage your database, you could simply
如果您使用 PHPmyAdmin 来管理您的数据库,您可以简单地
- Select
YOUR_TABLE
- Navigate to
More
- Then, navigate to
Operations
- There you will find an
AUTO_INCREMENT
field that you can alter:
- 选择
YOUR_TABLE
- 导航
More
- 然后,导航到
Operations
- 在那里你会找到一个
AUTO_INCREMENT
你可以改变的字段:
回答by Moyed Ansari
Reset the auto increment value for a MySQL table
ALTER TABLE `users` AUTO_INCREMENT = 1;
回答by nghiepit
SET @num := 0;
UPDATE your_table SET id = @num := (@num+1);
ALTER TABLE your_table AUTO_INCREMENT =1;
I think this will do it
我认为这会做到