美文网首页
8.23 cascade

8.23 cascade

作者: 鲸鱼酱375 | 来源:发表于2019-08-24 03:47 被阅读0次

    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

    相关文章

      网友评论

          本文标题:8.23 cascade

          本文链接:https://www.haomeiwen.com/subject/cvffectx.html