Re: reindex primary key autoincrement at mysql

From: Axel Schwenke <axel.schwenke_at_gmx.de>
Date: Fri, 29 Dec 2017 11:42:52 +0100
Message-ID: <p2567c$qb0$1_at_dont-email.me>


[Quoted] On 29.12.2017 10:51, Jakub wrote:
>
> How to re index primary key autoincrement column

[Quoted] I can only guess what you mean by "re index the PK", but if you want to change the PK of existing rows, i.e. to remove gaps in the numbers, then the simple answer is: YOU NEVER DO THAT.

The PK has only one purpose: to uniquely identify a row; and in most cases to do so for the life time of the whole database (which may well exceed the life time of a single row). That means that a PK is never assigned twice, not even after the original row has been deleted. Not even if the row existed only spuriously, i.e. as part of a rolled back transaction.

If you need a running counter, then create one on the fly. Or if your needs require that, add another field to your table. But DONT MESS WITH THE PK! Received on Fri Dec 29 2017 - 11:42:52 CET

Original text of this message