Friday, November 16, 2007

Statistics on a Table

Query to find out Index on Table

SELECT OWNER,
TABLE_NAME,
COUNT(*) INDEX_COUNT
FROM DBA_INDEXES
where OWNER not in ('SYS','SYSTEM')
and table_name = 'Tabel Name'
group by OWNER, TABLE_NAME

Query to find out column of an Index

SELECT TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
INDEX_NAME from dba_ind_columns WHERE TABLE_NAME = 'Table name'

Query to find out when the table was last analyzed and by what percentage

SELECT
NUM_ROWS,
SAMPLE_SIZE,
ROUND((SAMPLE_SIZE/NUM_ROWS)*100) "SAMPLE%",
TO_CHAR(last_analyzed,'DD-MM-YYYY:HH24:MI:SS') "Last_Analyzed"
FROM dba_tables
WHERE table_name ='Table_name';

No comments: