renumber primary key

前端 未结 6 1007
天命终不由人
天命终不由人 2021-01-12 03:31

How would I reset the primary key counter on a sql table and update each row with a new primary key?

6条回答
  •  逝去的感伤
    2021-01-12 04:31

    I would add another column to the table first, populate that with the new PK.

    Then I'd use update statements to update the new fk fields in all related tables.

    Then you can drop the old PK and old fk fields.

    EDIT: Yes, as Ian says you will have to drop and then recreate all foreign key constraints.

提交回复
热议问题