Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Resetting the index count to 0

Tags:

I need to reset my table counter back to 0 - is there a MySQL command for this?

like image 332
somejkuser Avatar asked Nov 25 '09 18:11

somejkuser


People also ask

Does MySQL count from 0 or 1?

The first element of arrays (in most programming languages) has an id (index) of 0. The first element (row) of MySQL tables has an (auto incremented) id of 1.

How do I reset Autoincrement?

In MySQL, the syntax to reset the AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = value; table_name. The name of the table whose AUTO_INCREMENT column you wish to reset.

Do we need to rebuild index in MySQL?

Indexes help to search for rows corresponding to a WHERE clause with particular column values very quickly so if the index is not working properly, then we must use the REINDEX command to operate and rebuild the indexes of table columns to continue the access of data.

Does truncate table reset auto increment?

The TRUNCATE TABLE statement removes all the data from a table and resets the auto-increment value to zero.


1 Answers

That's easy:

ALTER TABLE tablename AUTO_INCREMENT=0; 
like image 120
Andomar Avatar answered Oct 13 '22 07:10

Andomar