How do I reset sequence numbers to become consecutive?

前端 未结 5 1445
清歌不尽
清歌不尽 2020-12-19 06:50

I\'ve got a mysql table where each row has its own sequence number in a \"sequence\" column. However, when a row gets deleted, it leaves a gap. So...

1
2
3
         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-19 07:32

    I'd say don't bother. Reassigning sequential values is a relatively expensive operation and if the column value is for ordering purpose only there is no good reason to do that. The only concern you might have is if for example your column is UNSIGNED INT and you suspect that in the lifetime of your application you might have more than 4,294,967,296 rows (including deleted rows) and go out of range, even if that is your concern you can do the reassigning as a one time task 10 years later when that happens.

提交回复
热议问题