#1.创建普通索引
-- 语法:alter table 表名 add index|key [索引名][索引类型](字段名[长度][asc|desc])
-- 列如:创建表book6,给表中给sno添加普通索引
create table book6(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
alter table book6
add index(sno)
#2.创建唯一索引 unique
-- 语法:alter table 表名add unique [index|key] [索引名][索引类型](字段名[长度][asc|desc])
-- 列如:创建表book7,给表中给name添加唯一索引
create table book7(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
alter table book7
add unique index(name)
#3.创建主键索引 primary key
-- 语法:alter table 表名 add primary key [index|key] [索引名][索引类型](字段名[长度]
-- 列如:创建表book8,给表中给sno添加主键索引
create table book8(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
alter table book8
add primary key(sno)
#4.创建全文索引 fulltext
-- 语法:alter table 表名add fulltext [index|key] [索引名][索引类型](字段名
-- 列如:创建表book9,给表中给sinfo添加全文索引
create table book9(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
alter table book9
add fulltext index(sinfo)
#5.创建空间索引 spatial
-- 语法:alter table 表名add spatial [index|key] [索引名][索引类型](字段名
-- 列如:创建表book10,给表中给sloc添加空间索引
create table book10(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
alter table book10
add spatial index(sloc)
#6.复合索引
-- 语法:alter table 表名add index|key [索引名][索引类型](字段名1[长度][asc|desc],字段名2[长度][asc|desc])
-- 列如:创建表book11,给表中给sno和name添加复合索引
create table book11(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
alter table book11
add index(sno,name)
#查看索引
show index from book11