1.創建表,查看錶結構
-- 表存在則刪除
drop table if exists idnex1;
-- 建表
create table index1(
id int primary key auto_increment, --主鍵索引
name varchar(32) not null,
age tinyint not null,
intro text,
unique key (name), --唯一索引 unique key (字段名稱)
index (age), --普通索引 index (字段名稱)
fulltext index(intro), --全文索引 fulltext index(字段名稱)
index(name,age) --複合索引 index(字段名稱,字段名稱)
)engine myisam charset utf8;
-- 查看錶結構
show create table index1;
演示圖
-- alter增加索引
drop table if exists idnex2;
create table index2(
id int primary key auto_increment,
name varchar(32) not null,
age tinyint not null,
intro text
)engine myisam charset utf8;
--增加索引
alter table index2 add unique key (name),add index(age),add fulltext index(intro),add index(name,age);
show create table index1;
1.刪除主鍵索引
alter table index2 drop primary key;
如果主鍵中用auto_increment 就得先修改
alter table index2 modify id int not null;
刪除普通索引 alter table 表名 drop index 字段名
alter table index2 drop index name;