跳转到内容

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

来自FC
FC留言 | 贡献2023年6月25日 (日) 09:51的版本 (创建页面,内容为“== sqlserver == <syntaxhighlight lang="sql"> 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; </syntaxhighlight> == mysql == <syntaxhighlight lang="mysql"> SELECT table_name AS "表名", round(((data_length + index_lengt…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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;