要查询数据表的索引以及数据量所占空间,可以使用以下的SQL语句:

SELECT
    t.table_name,
    i.index_name,
    i.index_type,
    i.column_name,
    t.table_rows,
    round(((t.data_length + t.index_length) / 1024 / 1024), 2) AS total_size_mb
FROM
    information_schema.tables t
    JOIN information_schema.statistics i ON t.table_schema = i.table_schema AND t.table_name = i.table_name
WHERE
    t.table_schema = 'your_database_name'
ORDER BY
    t.table_name,
    i.index_name;

your_database_name 替换为你要查询的数据库名称。

这个查询将返回数据表的名称、索引的名称、索引的类型、索引的列名、数据表的行数以及数据表和索引所占空间的总大小(以MB为单位)

sql查询数据表索引以及数据量所占空间

原文地址: https://www.cveoy.top/t/topic/iVts 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录