How to update id set from 1?

前端 未结 4 1343
清歌不尽
清歌不尽 2021-01-03 03:46

I have an id i.e primary key and auto increment. Is there any query to update my existing id and make my id start from 1 and next id 2

4条回答
  •  旧时难觅i
    2021-01-03 04:38

    In my opinion you shouldn't mess with auto_increment columns at all. Let them be as they are. Their only job is to identify a row uniquely. If you want a nice serial number use another column (make it unique if you wish)!

    You will always run into trouble and there will always happen things, that mess with your nice 1, 2, 3, ... sequence. A transaction gets rolled back? Boom, your sequence is 1, 2, 3, 5, ... instead of your intended 1, 2, 3, 4, ...

    This can also be a very heavy operation. An auto_increment column is always also a primary key. Every other index on this table includes the primary key. Every time you reset your auto_increments, every index on this table is rewritten.

    So my advice is, don't mess with auto_increments.

提交回复
热议问题