sql - MySQL table reorder -


i have table like

id - data
1 - ...
2 - ...
4 - ...
5 - ...
8 - ...
12 - ...

the table long, thousands ids. @ ids, there "empty" numbers between of them. want reorder ids have no empty ones.

table should like
1 - ...
2 - ...
3 - ...
4 - ...
etc.

how query like?

i don't advocate re-numbering ids. id column should primary key table, , gaps don't make difference. if used foreign key references, messing database.

but, can as:

set @rn = 0;  update `table` t     set t.id = (@rn := @rn + 1)     order t.id; 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -