How to recalculate primary index?
Posted
by
JohnM2
on Stack Overflow
See other posts from Stack Overflow
or by JohnM2
Published on 2011-01-05T08:42:27Z
Indexed on
2011/01/05
8:53 UTC
Read the original article
Hit count: 196
mysql
I have table in mysql database with autoincrement PRIMARY KEY. On regular basis rows in this table are being deleted an added. So the result is that value of PK of the latest row is growing very fast, but there is not so much rows in this table.
What I want to do is to "recalculate" PK in this way, that the first row has PK = 1, second PK = 2 and so on. There are no external dependencies on PK of this table so it would be "safe".
Is there anyway it can be done using only mysql queries/tools? Or I have to do it from my code?
© Stack Overflow or respective owner