在建表过程中,使用ID作为唯一标识。一般采用数字串,比如从1到xxx,或者20200215xxxx等。
如果要用户名要唯一就需要使用唯一键了。
唯一但不需要是主键,就使用唯一键
如下
create table test1(
id int primary key auto_increment,
username varchar(16) unique
)charset utf8;
create table test2(
id int primary key auto_increment,
username varchar(16),
unique key(username)
)charset utf8;
create table test3(
id int primary key auto_increment,
username varchar(16)
)charset utf8;
alter table test3 add unique key(username);
查看下:
上面是命令行,只要稍微看得懂就行了。下面是用工具操作:
工具还是简单啊