1.更改或者删除mysql的主键
删除主键
alter table 表名 drop primary key;
然后再增加主键
alter table 表名 add primary key(字段);
2.更改或者删除mysql的UNIQUE约束
添加unique约束
alter table 表名 add unique key(字段);
修改unique约束
alter table 表名 modify 字段名 字段类型 约束;
alter table book modify book_name varchar(10) unique;
删除unique约束
alter table 表名drop key 字段名 或
alter table 表名 drop index 字段名;
3.unique和primary的区别
unique:一个表可以多个存在且可以为空
primary:一个表中只能存在一个且不能为空
知识点:primary key 和 unique 都可以组合使用
create table student(
-> id int,
-> age int,
-> primary key(id,age)
-> );