在定义外键可以对外键进行update 和delete 时对字表进行的操作
    image.png
    image.png

    1. mysql> create table parent(
    2. -> id int primary key);
    3. Query OK, 0 rows affected (0.01 sec)
    4. mysql> create table child (id int,parent_id int,foreign key(parent_id) references parent(id) on delete set null);
    5. Query OK, 0 rows affected (0.02 sec)
    6. mysql> insert into parent values (1),(2),(3);
    7. Query OK, 3 rows affected (0.00 sec)
    8. Records: 3 Duplicates: 0 Warnings: 0
    9. mysql> insert into child values(1,1),(2,2),(3,3);
    10. Query OK, 3 rows affected (0.01 sec)
    11. Records: 3 Duplicates: 0 Warnings: 0
    12. mysql> delete from parent where id=1;
    13. Query OK, 1 row affected (0.01 sec)
    14. mysql> select * from child;
    15. +------+-----------+
    16. | id | parent_id |
    17. +------+-----------+
    18. | 1 | NULL |
    19. | 2 | 2 |
    20. | 3 | 3 |
    21. +------+-----------+
    22. 3 rows in set (0.00 sec)
    23. mysql>