drgd73844 2014-08-31 22:51
浏览 5

mySQL主键奇怪

I have a script which INSERT's data into a table and then later on when you INSERT new data it DELETE's the previous record/s and INSERT's the current data set.

The only issue is that the primary key gets wacked.

e.g. first four rows

1
2
3
4

then when i delete these and enter new data

5
3
4
6

note: the above numbers represent primary key id auto incrementations

Why does the incrementation become confused almost?

  • 写回答

2条回答 默认 最新

  • donglue8180 2014-08-31 22:53
    关注

    Auto-increment number do not get confused. They are unique over the table and that is the only purpose they have.

    If you select the data then the DB will grab the records as fast as possible and if you do not specify a specific order then the records are returned in an unpredictable order.

    That means if you specify

    select * from your_table
    order by id
    

    Then the records have incrementing numbers. If you delete records then the gabs won't be filled.

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂