MySQL之——索引

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/l1028386804/article/details/90080168

转载请注明出处:https://blog.csdn.net/l1028386804/article/details/90080168

创建索引

创建表的时候创建索引

语法:

create table table_name [col_name data_type] [unique|fulltext|spatial] [index|key] [index_name] (col_name [length]) [asc|desc]

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

1.alter table语法:
alter table table_name add [unique|fulltext|spatial] [index|key] [index_name] (col_name[length],...) [asc|desc]
2.create index语法:
create [unique|fulltext|spatial] index index_name on table_name (col_name[length],...) [asc|desc]

示例

这里,以创建空间索引类型为例说明
创建表的时候创建索引:

create table t7(g geometry not null, spatial index spatIdx(g)) engine=MyISAM;

在已经存在的表上创建索引:
创建表t7,在表t7的空间数据类型字段g上创建名称为spatIdx的空间索引,SQL语句如下:

create table t7(g geometry not null) engine=MyISAM;

创建索引:

alter table方式:
alter table t7 add spatial index spatIdx(g);
create index方式:
create spatial index spatIdx on t7(g);

查看索引

mysql> show index from t7 \G
*************************** 1. row ***************************
        Table: t7
   Non_unique: 1
     Key_name: spatIdx
 Seq_in_index: 1
  Column_name: g
    Collation: A
  Cardinality: NULL
     Sub_part: 32
       Packed: NULL
         Null: 
   Index_type: SPATIAL
      Comment: 
Index_comment: 
1 row in set (0.00 sec)

删除索引

1.alter table语法:
alter table table_name drop index index_name;
2.drop index语法:
drop index index_name on table_name;

猜你喜欢

转载自blog.csdn.net/l1028386804/article/details/90080168