如何查看我的数据库是否有索引?
如果是特定的桌子呢?
如何查看我的数据库是否有索引?
如果是特定的桌子呢?
当前回答
如果我们知道下面的索引名,我们可以直接看到表上的索引:
Select * from all_indexes where index_name= 'your index'
其他回答
我提出这样的质疑:
SELECT DISTINCT s.*
FROM INFORMATION_SCHEMA.STATISTICS s
LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t
ON t.TABLE_SCHEMA = s.TABLE_SCHEMA
AND t.TABLE_NAME = s.TABLE_NAME
AND s.INDEX_NAME = t.CONSTRAINT_NAME
WHERE 0 = 0
AND t.CONSTRAINT_NAME IS NULL
AND s.TABLE_SCHEMA = 'YOUR_SCHEMA_SAMPLE';
您已找到所有索引索引。
把。
查询数据库中所有已禁用的索引
SELECT INDEX_SCHEMA, COLUMN_NAME, COMMENT
FROM information_schema.statistics
WHERE table_schema = 'mydb'
AND COMMENT = 'disabled'
如果你想一次性查看所有数据库的所有索引:
use information_schema;
SELECT * FROM statistics;
按顺序获取一列中每个索引的所有索引列。
SELECT table_name AS `Table`,
index_name AS `Index`,
GROUP_CONCAT(column_name ORDER BY seq_in_index) AS `Columns`
FROM information_schema.statistics
WHERE table_schema = 'sakila'
GROUP BY 1,2;
裁判:http://blog.9minutesnooze.com/mysql-information-schema-indexes/
SHOW INDEX FROM mytable FROM mydb;
SHOW INDEX FROM mydb.mytable;
见文档。