Search This Blog

Google Analytics

Sunday, January 14, 2024

Oracle: Find out total number of records of all tables

An efficient method to find out the total record counts of all tables in an Oracle database.
select table_name,
  to_number(extractvalue(xmltype(dbms_xmlgen.getxml('select count(*) c from '||owner||'.'||table_name)),'/ROWSET/ROW/C')) as count
from all_tables
where owner = 'SchemaName';

Hope it helps.

MSSQL: Find out total number of records of all tables

An efficient method to find out the total record counts of all tables in a MSSQL database.
SELECT tbl.name, CAST(p.rows AS int) 'count', tbl.schema_id, SCHEMA_NAME(tbl.schema_id) schema_name
FROM
  sys.tables AS tbl
  INNER JOIN sys.indexes AS idx ON idx.object_id = tbl.object_id AND idx.index_id < 2
  INNER JOIN sys.partitions AS p ON p.object_id = CAST(tbl.object_id AS int) AND p.index_id = idx.index_id
--WHERE ((SCHEMA_NAME(tbl.schema_id) = 'dbo'))
ORDER BY 2 DESC

Hope it helps.

Popular Posts