为什么查看表结构依旧是PRI
来源:1-10 主键和唯一索引操作
复java_n
2020-10-18 10:31:06
# 具体遇到的问题
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
在
create database if not exists inde;
use inde;
create table test_index(
id int not null unique
);
alter table test_index
drop index id;
alter table test_index
add unique key uni_id(id);
1回答
同学你好,当执行到如下语句后,test_index的id并不是主键PRI

当同学执行了alter table test_index add unique key uni_id(id);,在id字段前加了unique key
unique key 也有两个作用,一是约束作用,规范数据的唯一性,但同时也在这个key上建立了一个唯一索引;所以会出现key为PRI的现象。
如果同学想表达的不是这个意思,还麻烦同学具体描述一下。
相似问题