mysql索引操作
查看表索引
show index from school;
desc school;
添加普通索引
alter table school add index idx_name(`name`);
create index index_name on school(`name`);
添加唯一索引
create unique index uni_name on school(`name`);
alter table school add unique uni_name(`name`);
添加主键
alter table school add primary key(`id`);
添加AUTO_INCREMENT约束
alter table school modify column `id` bigint(20) NOT NUll AUTO_INCREMENT COMMENT 'id';
删除普通索引
drop index index_name on school;
alter table school drop index idx_name;
删除唯一索引
alter table school drop index uni_name;
ALTER TABLE tablename ADD PRIMARY KEY (列的列表);
删除主键
删除id的auto_increment约束
alter table school change id id int;
删除id的primary key约束
alter table school drop primary key;

浙公网安备 33010602011771号