1) create table infos (id int(4),name varchar(10));
create index id_index on infos (di);
2) alter table infos add index name_index (name);
3) create table num (id int,index id_index(id));
唯一索引
与 ”普通索引“ 基本相同
与普通索引的区别是索引列的所有值只能出现一次,即必须唯一
唯一索引允许为空,但空只能有一次
create unique index unique_name on info(name);
主键索引
是一种特殊的唯一索引,指定为 “PRIMARY KEY”
一个表只能有一个主键,不允许有空值
唯一且非空
create table info (id int(3) not null primary key auto_increment,......)
组合索引(单列索引与多列索引)
可以是单列上创建的索引,也可以是在多列上创建的索引
最左原则,从左往右依次执行
create table user(
name varchar(9),
age int(3),
sex tinyint(1),
index user(name,age,sex)
);
全文索引
索引类型为FULLTEXT
1) 在已存在的表上创建全文索引
create fulltext index content_tag_fulltext
on fulltext_test(content,tag);
2) alter 创建全文索引
alter table info add fulltext index addr_index(addresss);