Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql ID auto increment doesn't starts from 0

i have a table with ID , this ID is auto increment and primary key ,the first time i inserted to that table , the ID starts from 0 , but after i removing all the values from that table and inserted again to it , the ID doesn't start from 0 , but starts from the last value that ID had , what is going wrong please ? can i reset the value to 0 ?

like image 228
LinCR Avatar asked May 25 '12 11:05

LinCR


1 Answers

You may either truncate the table using

TRUNCATE `table`

Truncate will delete all of the data in the table. Note that using TRUNCATE will also not fire any DELETE triggers like DELETE.

Or you can reset the count using

ALTER TABLE `table` AUTO_INCREMENT = 1

It is however the expected behavior. Don't do the latter unless the table is truly empty.

like image 111
Ben Swinburne Avatar answered Oct 17 '22 02:10

Ben Swinburne