<pre>
create procedure sp_profile_tables
as
-- Purpose: "Profiles" Sybase tables by number of rows in each table.
-- Tables are grouped into ranges. The first ranges are 0 rows, 1 row,
-- 2-4 rows, 5-9 rows,
-- 10-19 rows, etc. The ranges become wider as the magnitude increases.

-- Notes: rowcnt() and reserved_pgs() are system functions
-- which use columns in the sysindexes table.
-- rowcnt(doampg) returns the approximate number of rows
-- reserved_pgs(id,doampg) returns the number of reserved data pages.

-- This technique is applicable to other data. You can profile bank
-- accounts by deposit size,
-- customers by number of purchases, etc. Just replace rowcnt(doampg)
-- with the column
-- to group by and add in the other columns to sum. Don't change any of
-- the funny character stuff.
-- The only restriction is the new column must be an integer 0 or
-- greater (no negatives).
-- The width and indentation of the pyramid are set by the "24" and "11"
-- in the calculation,
-- which you can adjust.

-- Written by Bob Munson, 74451.1500@compuserve.com
-- This procedure appears in an article in Exploring Sybase SQL Server
-- magazine.
-- 9420 Bunsen Parkway, Suite 300; Louisville, KY  40220

Select 
  "Row Range"= 
    substring(space(11-char_length(convert(varchar,rowcnt(doampg)))) +
    substring("0122255555",
   
charindex(substring(convert(varchar,rowcnt(doampg)),1,1),"0123456789"),1)
+
    replicate("0",char_length(convert(varchar,rowcnt(doampg)))-1) +"-" +
    substring("0144499999",
   
charindex(substring(convert(varchar,rowcnt(doampg)),1,1),"0123456789"),1)
+
    replicate("9",char_length(convert(varchar,rowcnt(doampg)))-1),1,24),
 "Tables"=count(*),
 "Megs"=sum(reserved_pgs(id,doampg))/512

From sysindexes
Where indid <=1 -- Skip non clustered indexes
   and id >=100 -- Skip system tables
Group by
   -- This is the same calculation as "Row Range"
   substring(space(11-char_length(convert(varchar,rowcnt(doampg)))) +
   substring("0122255555",
  
charindex(substring(convert(varchar,rowcnt(doampg)),1,1),"0123456789"),1)
+
   replicate("0",char_length(convert(varchar,rowcnt(doampg)))-1) +"-" +
   substring("0144499999",
  
charindex(substring(convert(varchar,rowcnt(doampg)),1,1),"0123456789"),1)
+
   replicate("9",char_length(convert(varchar,rowcnt(doampg)))-1),1,24)

