MySQL has a SQL query "SHOW INDEX FROM" that returns indexes from a table. E.g. - the following query will show all indexes for the product table: -
SHOW INDEXES FROM products \G
It returns a table with type, column_name, table_name, etc. and displays the output with all indexes and primary keys as -
*************************** 1. row *************************** Table: products Non_unique: 0 Key_name: PRIMARY Seq_in_index: 1 Column_name: product_id Collation: A Cardinality: 0 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: Index_comment:
To simply display the primary key from the table, use: -
SHOW INDEXES FROM table_name WHERE Key_name = 'PRIMARY'
priya gupta Apr 18 '16 at 12:31 on 2016-04-18 12:31
source share