How to update primary key

前端 未结 6 1834
萌比男神i
萌比男神i 2020-11-29 07:03

Here is my problem - I have 2 tables:

  1. WORKER, with columns |ID|OTHER_STAF| , where ID is primary key
  2. FIRM, with columns |FPK|ID|SOME
6条回答
  •  攒了一身酷
    2020-11-29 07:57

    You shouldn't really do this but insert in a new record instead and update it that way.
    But, if you really need to, you can do the following:

    • Disable enforcing FK constraints temporarily (e.g. ALTER TABLE foo WITH NOCHECK CONSTRAINT ALL)
    • Then update your PK
    • Then update your FKs to match the PK change
    • Finally enable back enforcing FK constraints

提交回复
热议问题