if exists (select * from sysobjects where id = object_id('dbo.ps_rowcount') and sysstat & 0xf = 4) drop procedure dbo.ps_rowcount GO create procedure ps_rowcount @NamesOrCount char(1) = NULL as /************************************************************************************************** description: returns rowcounts for all tables in the current database, or if @tablename is provided, for that table only. modified by: Paul Silveira psilveira@lojack.com caveat: this procedure makes use of sysindexes, so make sure all indexes are up-to-date **************************************************************************************************/ declare @dbname varchar(32) set nocount on IF UPPER(@NamesOrCount) = 'C' BEGIN SELECT o.name, i.rows FROM sysobjects o INNER JOIN sysindexes i ON (o.id = i.id) WHERE o.type = 'u' AND i.indid < 2 ORDER BY i.rows desc, o.name END ELSE IF UPPER(@NamesOrCount) = 'N' BEGIN SELECT o.name, i.rows FROM sysobjects o INNER JOIN sysindexes i ON (o.id = i.id) WHERE o.type = 'u' AND i.indid < 2 ORDER BY o.name, i.rows END ELSE BEGIN PRINT "No parameter was entered... C or N " PRINT "Therefore the output will be the default, or Column Count" SELECT o.name, i.rows FROM sysobjects o INNER JOIN sysindexes i ON (o.id = i.id) WHERE o.type = 'u' AND i.indid < 2 ORDER BY i.rows desc, o.name END GO