make an ID in a mysql table auto_increment (after the fact)

前端 未结 7 1495
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 20:09

I acquired a database from another developer. He didn\'t use auto_incrementers on any tables. They all have primary key ID\'s, but he did all the incrementing manually, in

7条回答
  •  盖世英雄少女心
    2020-11-30 20:23

    As long as you have unique integers (or some unique value) in the current PK, you could create a new table, and insert into it with IDENTITY INSERT ON. Then drop the old table, and rename the new table.

    Don't forget to recreate any indexes.

提交回复
热议问题