mysql语句 索引操作

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql语句 索引操作相关的知识,希望对你有一定的参考价值。

 

 

创建索引:(help create index;)

CREATE INDEX indexName ON tableName(Coll,Coll....);

ALTER TABLE tableName ADD INDEX indexName(Coll,Coll);

 

eg:
联合索引:
create index Sage_Sdept on student(Sage,Sdpt(10))
create index d_a_p on student(dateline,ader(20),pos(20));

 

 

删除索引:

ALTER TABLE tableName DROP indexName;

DROP INDEX indexName ON tableName;

 

 

查看表的索引:

mysql> show index from proc;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| proc | 0 | PRIMARY | 1 | db | A | NULL | NULL | NULL | | BTREE | | |
| proc | 0 | PRIMARY | 2 | name | A | NULL | NULL | NULL | | BTREE | | |
| proc | 0 | PRIMARY | 3 | type | A | 48 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

以上是关于mysql语句 索引操作的主要内容,如果未能解决你的问题,请参考以下文章

mysql语句 索引操作

Mysql表读写索引等操作的sql语句效率优化问题

mysql 删除和修改操作会是有索引吗

MySQL入门

Mysql操作之部分DDL语句

MySQL之唯一索引外键的变种SQL语句数据行操作补充