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

2 Comments

Comments have been disabled for this content.