How can I reset the AUTO_INCREMENT
of a field? I want it to start counting from 1
again.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- sqlyog export query result as csv
To update latest plus one id
Simply like this:
reference: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
I think this will do it
You can reset the counter with:
For InnoDB you cannot set the
auto_increment
value lower or equal to the highest current index. (quote from ViralPatel):See How to Reset an MySQL AutoIncrement using a MAX value from another table? on how to dynamically get an acceptable value.
There is a very easy way with phpmyadmin under the "operations" tab, you can set, in the table options, autoincrement to the number you want.
Here is my solution, but I will not advise to do this if your column has constraints or is connected as foreign key to other tables as it would have bad effects or will not even work.
> First : drop the column
> Second : recreate the column and set it as FIRST if you want it as the first column I assume.
This works well!