ITPub博客

首页 > 数据库 > MySQL > MySQL 5.5 删除索引的方法

MySQL 5.5 删除索引的方法

原创 MySQL 作者:feelpurple 时间:2016-06-04 11:11:19 0 删除 编辑
mysql> show keys from dept2;
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name              | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dept2 |          0 | PRIMARY               |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
| dept2 |          1 | idx_dept2_deptno      |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
| dept2 |          1 | idx_dept2_report_date |            1 | report_date | A         |           4 |     NULL | NULL   | YES  | BTREE      |         |               |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

方法①

mysql> drop index idx_dept2_deptno on dept2;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show keys from dept2;
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name              | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dept2 |          0 | PRIMARY               |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
| dept2 |          1 | idx_dept2_report_date |            1 | report_date | A         |           4 |     NULL | NULL   | YES  | BTREE      |         |               |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

--方法②

mysql> alter table dept2 drop index idx_dept2_report_date;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show keys from dept2;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dept2 |          0 | PRIMARY  |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26506993/viewspace-2113870/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-08-01

  • 博文量
    404
  • 访问量
    1674012