约束是作用与表中字段上的规则,用于限制存储在表中的数据。保证数据库中数据的正确、有效性和完整性。
分类:

注意:约束是作用于表中的字段上的,可以在创建表/修改表的时候添加约束。
外键约束:
语法:
添加外键:
crate table 表名(
字段名 数据类型,
......
constraint\] \[外键名称\] foreign key (外键字段名) references 主表 (主表列名) ); 或: alter table add constraint 外键名称 foreign key (外键字段名)references, 主表(主表列名); 删除外键: alter table 表名 drop foreign key 外键名称; 删除/更新行为:  alter table 表名 add constraint 外键名称 foreign key (外键字段) references 主表名(主表字段名) on update (cascade) on delete (cascade);