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
网友评论