Command SQL For List of Biggest Tables

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

--Set Format Parameters:

set linesize 150


set pagesize 200
col owner for a20
col table_name for a50

spool ALL.LST

--Query to get list of non-partitioned, non-clustered tables:


SELECT table_name, Round(sum(bytes)/1024/1024) MB FROM
(SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type
= 'TABLE'
UNION ALL
SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type =
'TABLE PARTITION'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.segment_name AND s.owner = l.owner AND s.segment_type =
'LOBSEGMENT'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.index_name AND s.owner = l.owner AND s.segment_type =
'LOBINDEX')
WHERE owner like 'SAPSR3%'
GROUP BY table_name, owner HAVING SUM(bytes)/1024/1024 > 1024 ORDER BY SUM(bytes)
desc;

spool off
spool TRANSPARENT.LST

--Query to get list of non-partitioned, non-clustered tables:


SELECT table_name, Round(sum(bytes)/1024/1024) MB FROM
(SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type
= 'TABLE'
UNION ALL
SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type =
'TABLE PARTITION'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.segment_name AND s.owner = l.owner AND s.segment_type =
'LOBSEGMENT'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.index_name AND s.owner = l.owner AND s.segment_type =
'LOBINDEX')
WHERE owner like 'SAPSR3%' and table_name not in (select sqltab from sapsr3.dd02l
where tabclass='CLUSTER') and table_name not in (select table_name from
dba_part_tables)
GROUP BY table_name, owner HAVING SUM(bytes)/1024/1024 > 1024 ORDER BY SUM(bytes)
desc;

spool off
spool PARTITIONED.LST

--Query to get list of partitioned tables:


SELECT table_name, Round(sum(bytes)/1024/1024) MB FROM
(SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type
= 'TABLE'
UNION ALL
SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type =
'TABLE PARTITION'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.segment_name AND s.owner = l.owner AND s.segment_type =
'LOBSEGMENT'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.index_name AND s.owner = l.owner AND s.segment_type =
'LOBINDEX')
WHERE owner like 'SAPSR3%' and table_name in (select table_name from
dba_part_tables)
GROUP BY table_name, owner HAVING SUM(bytes)/1024/1024 > 1024 ORDER BY SUM(bytes)
desc;

spool off
spool CLUSTERED.LST

--Query to get list of clustered tables:


SELECT table_name, Round(sum(bytes)/1024/1024) MB FROM
(SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type
= 'TABLE'
UNION ALL
SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type =
'TABLE PARTITION'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.segment_name AND s.owner = l.owner AND s.segment_type =
'LOBSEGMENT'
UNION ALL
SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE
s.segment_name = l.index_name AND s.owner = l.owner AND s.segment_type =
'LOBINDEX')
WHERE owner like 'SAPSR3%' and table_name in (select sqltab from sapsr3.dd02l where
tabclass='CLUSTER')
GROUP BY table_name, owner HAVING SUM(bytes)/1024/1024 > 1024 ORDER BY SUM(bytes)
desc;

spool off

You might also like