码迷,mamicode.com
首页 > 数据库 > 详细

Mysql索引

时间:2017-10-30 14:34:04      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:engine   而且   详解   myisam   text   ble   string   ...   logs   

创建索引和删除索引

1、在已经存在的表上创建索引

create [unique|fulltext|spatial] index 索引名 on 表名 (字段名 [(长度)] [asc|desc]); 

或者

alter table 表名 add [unique|fulltext|spatial] index 索引名 (字段名 [(长度)] [asc|desc]);

 2、创建表的时侯创建索引

create table 表名 (
                      字段名 数据类型 [完整性约束条件],
                      字段名 数据类型 [完整性约束条件],
                      ......
                      [unique|fulltext|spatial] index|key [索引名] (字段名 [(长度)][asc|desc])
) engine=myisam;

以上参数详解:

unique:唯一索引,该索引所在字段的值必须是唯一的。

fulltext:全文索引,它只能创建在 char、varchar、text 类型的字段上,而且,现在只有 myisam 引擎支持全文索引。

spatial:空间索引,它只能创建在 geometry、point、linestring、polygon 类型字段上,而且必须声明 not null ,储存引擎为 myisam 引擎。

长度:表示索引的长度。

asc和desc:asc 表示升序排序,desc 表示降序排序。 

 

删除索引

alter table 表名 drop index 索引名;

或者

drop index 索引名 on 表名;

Mysql索引

标签:engine   而且   详解   myisam   text   ble   string   ...   logs   

原文地址:http://www.cnblogs.com/lanchang/p/7753836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!