Reputation: 11961
I have a table called Person in MySQL. There is a column id
which has UNIQUE
and AUTO_INCREMENT
property and also a primary key. I want to reset the counter of id
so that it restarts from 1. I used the following SQL statement:
ALTER TABLE Person AUTO_INCREMENT=1;
But after I applied this change, the id
still starts from my last position (130), not from 1. So why this resetting doesn't work?
Upvotes: 3
Views: 1383
Reputation: 6146
Use TRUNCATE TABLE
as this will reset the autoincrement
From the documentation... From MySQL 5.0.13 on, the AUTO_INCREMENT counter is reset to zero by TRUNCATE TABLE, regardless of whether there is a foreign key constraint.)
Upvotes: 4