跳转到内容

查看数据库中数据表大小并降序排列

来自FC

sqlserver

SELECT 
    t.NAME AS "表名",
    SUM(p.reserved_page_count) * 8.0 / 1024 AS "大小(MB)"
FROM 
    sys.tables t
INNER JOIN 
    sys.dm_db_partition_stats p ON t.object_id = p.object_id
WHERE 
    p.index_id < 2
GROUP BY 
    t.NAME
ORDER BY 
    SUM(p.reserved_page_count) DESC;

mysql

SELECT 
    table_name AS "表名", 
    round(((data_length + index_length) / 1024 / 1024), 2) AS "大小(MB)" 
FROM 
    information_schema.tables 
WHERE 
    table_schema = 'your_database_name' 
ORDER BY 
    (data_length + index_length) DESC;