我试图在我的架构中找到一个表的大小。我试图通过dba_extent找到如下。
select segment_name,sum(bytes)/(1024*1024) size from dba_extent where segment_type='TABLE'
and segment_name = 'mytablename'
and owner ='myschemaname'
group by segment_name;
它提供2 MB,但不是2MB,我在日志中看到它的大小为800MB,而我正在导出schema.It在查询dba_segments时给出了相同的结果。任何人都可以在我出错的地方帮忙。谢谢你的时间。
答案 0 :(得分:-3)
尝试以下SQL:希望这会有所帮助:)
SELECT
tbl.NAME AS TableName,
idx.name as indexName,
prts.[Rows],
sum(a.total_pages) as TotalPages,
sum(a.used_pages) as UsedPages,
sum(a.data_pages) as DataPages,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB,
(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB,
(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
FROM
sys.tables tbl
INNER JOIN
sys.indexes idx ON tbl.OBJECT_ID = idx.object_id
INNER JOIN
sys.partitions prts ON idx.object_id = prts.OBJECT_ID AND idx.index_id = prts.index_id
INNER JOIN
sys.allocation_units a ON prts.partition_id = a.container_id
WHERE
tbl.NAME NOT LIKE 'dt%' AND
idx.OBJECT_ID > 255 AND
idx.index_id <= 1
GROUP BY
tbl.NAME, idx.object_id, idx.index_id, idx.name, prts.[Rows]
ORDER BY
object_name(idx.object_id)