tonga
tonga

Reputation: 11961

resetting AUTO_INCREMENT doesn't work

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

Answers (1)

Steph Locke
Steph Locke

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

Related Questions