Error #1062 Mysql Duplicate Entry for the key primary

I have big MySql table 'docs' (above 3 000 000 rows).
This table have column id --- primary key unsigned and did ----- unsigned.
Sometimes some rows deleted. But I need that autoincrement go 1234 and not 1479.
I perform sql request:

update docs set id=@num:=@num+1 where 0 in(select @num:=0)

and receive error #1062.

2 questions: 1. Why I have duplicate entry for the key primary? 2. How I can delete them?

Upvotes: 0

Views: 1003

Answers (1)

My idea is more easy (remove and add primary):
ALTER TABLE docsDROP id;
ALTER TABLE docs ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id);

Upvotes: 0

Related Questions