How to reorder a primary key?

前端 未结 5 1090
小蘑菇
小蘑菇 2021-01-01 06:21

I have a table of 5700 records. The primary key is an integer. Now I noticed that some values are missing. Like this:

100 data
101 data 
102 data
104 data
         


        
5条回答
  •  旧巷少年郎
    2021-01-01 06:55

    There is no point in doing this.

    IDs from deleted records are not re-used on purpose - to make sure that references from other tables to previously deleted records don't suddenly point to the wrong record, for example. It is not a good idea to try to change this.

    If you want a numbered list that has no holes, create a second int column that you re-order in your client program whenever necessary (i.e. when a record is deleted).

提交回复
热议问题