Search code examples
sybase

How to list all the user tables in Sybase along with their row count?


I would like to return all the tables and its count next to it. what is the quickest way to go about it?

I know in Oracle, you can do something like below, but not sure about Sybase:

declare n number;
begin
   for rec in (select object_name from user_objects where object_type='TABLE')
   loop
     execute immediate 'select count(*) from '||rec.object_name into n;
     dbms_output.put_line (rec.object_name||':'||n);
   end loop;
end;

Solution

  • Here is the Sybase sql that does the above:

    select ob.name,st.rowcnt 
    from sysobjects ob, systabstats st 
    where ob.type="U"  
    and st.id=ob.id 
    order by ob.name