1>创建普通索引
Mysql->create table aatest(
id int,
name varchar(20),
sexboolean,
index(id)); 使用 index设置id为普通索引。
Mysql> show create table aatest\G; 查看一下表详细结构
Mysql>explain select * from aatest where id=1 \G; 查看索引是否被使用。
2>建立唯一索
唯一索引使用unique进行约束
create table aatest2(
id int unique,
name varchar(20),
unique index aatest_id(id ASC)); 3>创建全文索引
create table aatest3(
id int,
info varchar(20),
fulltext index aatest3_info(info)); *******5.6版本已支持全文索引
4>创建单列索引
create table aatest4(
id int,
subject varchar(30),
index aatest4_st(subject(10)));subject(10)指定索引的长度 5>创建多列索引
多列索引,是在表上多个字段创建一个索引。
create table aatest5(
id int,
name varchar(20),
sex char(4),
index aatest5_ns(name,sex));5》在已经有的表上建立索引: ……
语法:
create [unique (北联网教程,专业提供视频软件下载)