Exact Meaning of MySQL's Foreign Key 'on delete restrict' Clause

后端 未结 2 532
孤独总比滥情好
孤独总比滥情好 2020-12-28 11:36

I have two MySQL tables: collections and privacy_level.
I define them with a foreign key relationship as such:



        
相关标签:
2条回答
  • 2020-12-28 12:20

    Also you can use ON DELETE CASCADE, that means when you delete the parent all the children will be removed automatically, this is useful when you have a table associated with another that contains some parameters or settings.

    0 讨论(0)
  • 2020-12-28 12:23

    ON DELETE RESTRICT means you can't delete a given parent row if a child row exists that references the value for that parent row. If the parent row has no referencing child rows, then you can delete that parent row.

    ON DELETE RESTRICT is pretty much superfluous syntax, because this is the default behavior for a foreign key anyway.

    0 讨论(0)
提交回复
热议问题