Tuesday, August 24, 2010

Sql query to list rowcount for all table in schema

Some times we face problems that require to find no. of rows in all tables in schema .

Following are sql queries that list table name and their row count,

For Microsoft SQL Server:
SELECT distinct(t.name) AS table_name,i.rows
FROM sys.tables AS t
INNER JOIN sys.sysindexes AS i ON t.object_id = i.id
 

For Oracle
select table_name,num_rows counter
from dba_tables 
where owner = 'XXX'
order by table_name;

No comments: