重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2352|回复: 0
打印 上一主题 下一主题

mysql中查询某张表的所有索引的方法

[复制链接]
跳转到指定楼层
楼主
发表于 2015-4-11 12:09:36 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

mysql查询索引的方法  :


比如想查emp的索引:
可以使用以下语句:

show index from emp;

也可以通过sql语句来查


select tab.name as "table_name",idx.name as "index_name",
       fld.name as "index_column_name",fld.pos as "index_column_pos"
  from
        information_schema.innodb_sys_indexes idx,
        information_schema.innodb_sys_tables tab,
       information_schema.INNODB_SYS_FIELDS fld
  where idx.table_id=tab.table_id
     and idx.index_id=fld.index_id
     and tab.name like  'sztech/emp'


mysql> show index from sztech.emp;
+-------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name      | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| emp   |          1 | idx_emp_empid |            1 | empid       | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)

mysql> select tab.name as "table_name",idx.name as "index_name",
    ->        fld.name as "index_column_name",fld.pos as "index_column_pos"
    ->   from
    ->         information_schema.innodb_sys_indexes idx,
    ->         information_schema.innodb_sys_tables tab,
    ->        information_schema.INNODB_SYS_FIELDS fld
    ->   where idx.table_id=tab.table_id
    ->      and idx.index_id=fld.index_id
    ->      and tab.name like  'sztech/emp'
    -> ;
+------------+---------------+-------------------+------------------+
| table_name | index_name    | index_column_name | index_column_pos |
+------------+---------------+-------------------+------------------+
| sztech/emp | idx_emp_empid | empid             |                0 |
+------------+---------------+-------------------+------------------+
1 row in set (0.00 sec)

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-11-25 04:48 , Processed in 0.107825 second(s), 21 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表