Try :
select COUNT(*) from user_tables;
OR
Select COUNT(table_name) from user_tables
num_rows
returns no.of rows value is updated by DBMS_STATS
. So it does not contain the current number of rows in the table but an approximation calculated the last time DBMS_STATS
was run.
Update : For counting all the rows in all tables in database:
1. Better way:
`select table_name, num_rows from user_tables;`
OR Alternatively
2. using function(not recommended)
create or replace
function get_rows( p_tname in varchar2 ) return number
as
l_columnValue number default NULL;
begin
execute immediate
'select count(*)
from ' || p_tname INTO l_columnValue;
return l_columnValue;
end;
For running function after creating using above code:
select user, table_name,
get_rows( user||'.'||table_name) cnt
from user_tables
Please note this is for oracle. For Sql server refer :
How to fetch the row count for all tables in a SQL SERVER database