List all tables and their row counts

Just find few useful tips/tool when I try to compare the schema and content of two SQL databases:

  1. DBComparer (free)
  2. Find out DB lock: select distinct object_name(a.rsc_objid), a.req_spid, b.loginame from master.dbo.syslockinfo a (nolock) join master.dbo.sysprocesses b (nolock) on a.req_spid=b.spid where object_name(a.rsc_objid) is not null
  3. List all tables in database: SELECT * FROM sys.Tables
  4. List all tables and their row counts
SELECT 
    [TableName] = so.name, 
    [RowCount] = MAX(si.rows) 
FROM 
    sysobjects so, 
    sysindexes si 
WHERE 
    so.xtype = 'U' 
    AND 
    si.id = OBJECT_ID(so.name) 
GROUP BY 
    so.name 
ORDER BY 
    2 DESC
Published Wednesday, September 01, 2010 7:14 PM by Colt
Filed under:

Comments

# re: List all tables and their row counts

Tuesday, November 30, 2010 3:50 AM by Experts Comment

# re: List all tables and their row counts

Useful bit of kit Number 1

Friday, May 13, 2011 6:41 AM by HostingBest

# re: List all tables and their row counts

awesome man.its work for me

Tuesday, July 19, 2011 1:29 AM by shiv

Leave a Comment

(required) 
(required) 
(optional)
(required)