网站开发技术

记点笔记、 学点技术 欢迎交流建站技术。本站关注lamp技术

您尚未登录。

#1 2014-12-06 15:47:24

admin
管理员

mysql 中索引的删除,

索引的删除 有两种方法

第一: drop index index_name on tb_name;
第二: alter table tb_name drop index index_name;

创建一个表,添加索引

mysql> create table tb4 ( age int , name varchar(20), email varchar(20));
Query OK, 0 rows affected (0.26 sec)

mysql> alter table tb4 add index (age);
Query OK, 0 rows affected (0.50 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table  tb4 add unique (name);
Query OK, 0 rows affected (0.47 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> create index index_name on tb4 (email);
Query OK, 0 rows affected (0.65 sec)
Records: 0  Duplicates: 0  Warnings: 0

查看当前的索引

mysql> show  index from tb4;
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| tb4   |          0 | name       |            1 | name        | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               |
| tb4   |          1 | age        |            1 | age         | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               |
| tb4   |          1 | index_name |            1 | email       | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

删除索引

mysql> alter table tb4 drop index name;
Query OK, 0 rows affected (0.12 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table tb4 drop index index_name;
Query OK, 0 rows affected (0.11 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> drop index age on tb4;
Query OK, 0 rows affected (0.13 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> show index from tb4;
Empty set (0.00 sec)

索引的删除,都是删除的索引的名字, 如果创建索引的时候,没有指定名字, 那么名字就只字段的名字。


ipbbs.net

离线

页脚

Powered by FluxBB