--方法1: SELECT A.NAME, B.ROWS FROM SYSOBJECTS AS A INNER JOIN SYSINDEXES AS B ON A.ID = B.ID WHERE (A.TYPE = 'u') AND (B.INDID IN (0, 1)) ORDER BY B.ROWS DESC
--方法2: SELECT SCHEMA_NAME(T.SCHEMA_ID) AS [ SCHEMA ], T.NAME AS TABLENAME, I.ROWS AS [ ROWCOUNT ] FROM SYS.TABLES AS T, SYSINDEXES AS I WHERE T.OBJECT_ID = I.ID AND I.INDID <= 1 --如果只看总量,使用以下语句 SELECT SUM(ROWS) FROM SYS.TABLES AS T, SYSINDEXES AS I WHERE T.OBJECT_ID = I.ID AND I.INDID <= 1
统计数据库占用空间大小
1
EXEC sp_spaceused
MySql 数据量统计
简单快捷,直接查询数据库中所有行数
1 2 3
select sum(table_rows) as '记录数' from information_schema.tables -- where table_schema = 'esp' ;
查询所有数据库容量大小
1 2 3 4 5 6 7 8 9
select table_schema as '数据库', sum(table_rows) as '记录数', sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)', sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)' from information_schema.tables -- where table_schema = 'your_database_name' group by table_schema order by sum(data_length) desc, sum(index_length) desc;
查询所有数据库各表容量大小
1 2 3 4 5 6 7 8 9 10
select table_schema as '数据库', table_name as '表名', table_rows as '记录数', truncate(data_length/1024/1024, 2) as '数据容量(MB)', truncate(index_length/1024/1024, 2) as '索引容量(MB)' from information_schema.tables -- where table_schema = 'your_database_name' where table_schema = 'esp' order by table_schema asc, data_length desc, index_length desc;
查询单表每个索引大小
1 2 3 4 5 6 7 8 9 10 11
select sum(stat_value) pages, table_name, index_name, concat(round(sum(stat_value)/1000000 * @@innodb_page_size, 2), 'M') size from mysql.innodb_index_stats where table_name = 'user_info_index' and database_name = 'db_my_test' and stat_description LIKE 'Number of pages in the index' group by table_name, index_name;