一、MySQL
select table_name, #表名
sum(data_length+index_length)/(1024)/(1024) as total_mb, #總大小MB
sum(data_length)/(1024)/(1024) as data_mb, #數據文件大小MB
sum(index_length)/(1024)/(1024) as index_mb #索引大小MB
from information_schema.tables
where table_schema='ABC' group by table_name #ABC爲數據庫名稱
二、SqlServer
select name, #數據文件名稱
convert(float,size) * (8192.0/1024.0)/1024.0 #轉爲MB
from bserp3.dbo.sysfiles
三、Oracle
SELECT a.tablespace_name "表空間名",
total "表空間大小",
free "表空間剩餘大小",
(total - free) "表空間使用大小",
total / (1024 * 1024 * 1024) "表空間大小(G)",
free / (1024 * 1024 * 1024) "表空間剩餘大小(G)",
(total - free) / (1024 * 1024 * 1024) "表空間使用大小(G)",
round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free
FROM dba_free_space
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total
FROM dba_data_files
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
#查看每張表所佔大小
SELECT segment_name AS TABLENAME,
BYTES B,
BYTES/1024 KB,
BYTES/1024/1024 MB
FROM user_segments
WHERE segment_name='ABC' #ABC爲表名