8.23 cascade

1.Cascade Function

正常创建fk之后,如果删除主表的pk,受constraint限制,是会报错的

  • Causes changes to a Primary Key value to be reflected on the Foreign Key

  • Cascade is put on the Foreign Key and will monitor the Primary Key values it’s referencing

  • Delete or Update

  • A foreign key with cascade delete means that if a record in the parent table is deleted, then the corresponding records in the child table will automatically be deleted.

2.Different Cascade Options

  • Cascade
    The changes made will “cascade” or fall down to the FK
    Deletes will be logged ONLY for PK table
  • Set Null
    Give a null value in place of the FK value if there’s a change
    Orphan
  • Set Default
    Will set the value of the FK to be a default value
    Must have Default constraint
  • No Action
    There will be no action taken on the FK

Delete Mandatory �Update Optional

3.Pro’s and Con’s of using Cascade

Automated and will make things easier to change in regard to the Parent Child policy
Easier doesn’t equal better, as it’ll be easier to make a mistake
With no logging for cascaded deleted values, that information is gone
Has to be used on each FK

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容