How to update primary key

前端 未结 6 1860
萌比男神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条回答
  •  旧时难觅i
    2020-11-29 07:44

    If you are sure that this change is suitable for the environment you're working in: set the FK conditions on the secondary tables to UPDATE CASCADING.

    For example, if using SSMS as GUI:

    1. right click on the key
    2. select Modify
    3. Fold out 'INSERT And UPDATE Specific'
    4. For 'Update Rule', select Cascade.
    5. Close the dialog and save the key.

    When you then update a value in the PK column in your primary table, the FK references in the other tables will be updated to point at the new value, preserving data integrity.

提交回复
热议问题