drop table if exists t_vip;create table t_vip(id int,name varchar(255) not null unique);insert into t_vip(id,name) values (1,'zhangsan');insert into t_vip(id,name) values (2,'zhangsan'); #错误,unique约束insert into t_vip(id) values (3); #错误,not null约束
在MySQL当中,如果一个字段同时被not null 和 unique约束的话,该字段会自动变成主键
