mysql约束 电脑版发表于:2020/8/26 13:09 ####一:添加约束: 1.添加主键约束 alter table 表名 add [constrant] [约束名] primary key(字段名); 2.添加唯一约束 alter table 表名 add [constrant] unique(字段); 3.添加默认索引 alter table 表名 add column 字段名 set default 默认值 4.添加检查约束 create table 表名( 字段名 enum('男','女) ); 5.添加外键约束 alter table 表名 add [constrant] [约束名] foreign key(字段名) references 主表名(字段名); ####二:删除约束 1.删除主键约束 alter table 表名 drop primay key; 2.删除外键约束 alter table 表名 drop foreign key 约束名;