Mysql workbench foreign key options [Restrict, Cascade, Set Null, No Action], what do they do?

后端 未结 3 1703
生来不讨喜
生来不讨喜 2021-02-01 05:08

In foreign key options on update and on delete. What does each field [Restrict, Cascade, Set Null, No Action] do?

3条回答
  •  再見小時候
    2021-02-01 05:48

    The table containing the foreign key is called the referencing or child table, and the table containing the candidate key is called the referenced or parent table.

    Set NULL : Sets the column value to NULL when you delete the parent table row.

    CASCADE : CASCADE will propagate the change when the parent changes. If you delete a row, rows in constrained tables that reference that row will also be deleted, etc.

    RESTRICT : RESTRICT causes you can not delete a given parent row if a child row exists that references the value for that parent row.

    NO ACTION : NO ACTION and RESTRICT are very much alike. when an UPDATE or DELETE statement is executed on the referenced table, the DBMS verifies at the end of the statement execution that none of the referential relationships are violated. in short child row no concern if parent row delete or update.

提交回复
热议问题