表间关系——外键

建立:

  • 在新建表时建立:create table 表名(A int,B text,constraint 规则名 foreign key(字段名) references 表名(字段名));
  • 在以建好的表建立:alter table 表名 add constraint 规则名 foreign key(字段名) references 表名(字段名));
  • other:
    on update cascade 级联更新
    on delete cascade 级联删除
    set foreign_key_checks=0 禁用主键
    set foreign_key_checks=1 启用外键
    alter table 表名 drop foreign key 约束名 删除外键

**

猜你喜欢

转载自blog.csdn.net/weixin_45936162/article/details/106164417