I've previously posted how to get the indexes for a MySQL table using a "SHOW INDEXES" SQL query and in this post show an alternative way to get the indexes for a table using MySQL's INFORMATION_SCHEMA.
Example tables
The examples in this post uses a table structured as follows:
Get the indexes
This first query will get all the column name and the index type for all columns that are indexed, from the "test" database and "products" table:
For the example table this will return the following:
PRI indicates it is a primary key; UNI that it is indexed with a unique constraint; and MUL that it is a regular index.
Get the primary key(s)
The second example shows how to just get the primary keys from a table using the INFORMATION_SCHEMA, using the example "products" table from the "test" database again:
For the example table this would return:
0 comments:
Post a Comment