eLemEnt
eLemEnt

Reputation: 1801

mysql change auto_increment field from null to number of records

Hiii..

I had created one table in mysql...and inserted about 320 records in that table. Now I altered that table and added one auto_increment field. Now it is showing null value for that field in all records.

Guys please tell me trick to update all 320 record with 1 to 320 in that field.

update formData set ID = (select @rownum := @rownum + 1 AS rank from formData t, (select @rownum := 0)r); 

Upvotes: 0

Views: 22

Answers (1)

Venkatesh Panabaka
Venkatesh Panabaka

Reputation: 2154

I think below SQL useful to you.

SET @rank:=0;
UPDATE formData
SET ID=@rank:=@rank+1

Thank you.

Upvotes: 1

Related Questions