首页 > 数据库技术 > 详细

Mysql索引

时间:2017-10-30 12:42:05      阅读:208      评论:0      收藏:0      [点我收藏+]

创建索引和删除索引

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索引

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!