2

I am trying to find the size of a table in my schema. I've tried to find through dba_extent as follows.

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;

It gives as 2 MB, but no way it is 2MB and I've seen its size as some 800MB in the logs while i was exporting schema.It gave the same result when i query the dba_segments. Could anyone help where I gone wrong.thanks for your time.

Mat
  • 202,337
  • 40
  • 393
  • 406
cherry
  • 127
  • 9

1 Answers1

-3

Try below SQL : Hope this will help :)

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)
Hemant Patel
  • 184
  • 6